Skip to content

Commit

Permalink
chore: Generate New Types (#771)
Browse files Browse the repository at this point in the history
  • Loading branch information
AtelyPham authored Oct 1, 2024
1 parent 1c60a02 commit 27f174c
Show file tree
Hide file tree
Showing 14 changed files with 4,211 additions and 2,809 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/publish-types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Publish Types
# If changes are made to the types/src/** files
# Issue a new release to npm for the types package.
on:
workflow_dispatch:

push:
branches:
- main
Expand Down
8 changes: 4 additions & 4 deletions node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ where
C::Api: rpc_primitives_debug::DebugRuntimeApi<Block>,
C::Api: rpc_primitives_txpool::TxPoolRuntimeApi<Block>,
C::Api: BabeApi<Block>,
C::Api: sygma_runtime_api::SygmaBridgeApi<Block>,
// C::Api: sygma_runtime_api::SygmaBridgeApi<Block>,
C: BlockchainEvents<Block> + 'static,
C: HeaderBackend<Block>
+ HeaderMetadata<Block, Error = BlockChainError>
Expand All @@ -142,12 +142,12 @@ where
use sc_consensus_babe_rpc::{Babe, BabeApiServer};
use sc_consensus_grandpa_rpc::{Grandpa, GrandpaApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
use sygma_rpc::{SygmaBridgeRpcServer, SygmaBridgeStorage};
// use sygma_rpc::{SygmaBridgeRpcServer, SygmaBridgeStorage};

let mut io = RpcModule::new(());
let FullDeps { client, pool, deny_unsafe, eth, babe, select_chain, grandpa } = deps;

let BabeDeps { keystore, babe_worker_handle } = babe;
let Some(BabeDeps { keystore, babe_worker_handle }) = babe else { todo!() };

let GrandpaDeps {
shared_voter_state,
Expand Down Expand Up @@ -177,7 +177,7 @@ where
.into_rpc(),
)?;

io.merge(SygmaBridgeStorage::new(client.clone()).into_rpc())?;
// io.merge(SygmaBridgeStorage::new(client.clone()).into_rpc())?;

// Ethereum compatibility RPCs
let io = create_eth::<_, _, _, _, _, _, _, DefaultEthConfig<C, BE>>(
Expand Down
43 changes: 31 additions & 12 deletions types/scripts/generate-ts-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { join, resolve } = require('node:path')
const CWD = process.cwd()
const TYPES_DIR = join(CWD, 'types')
const METADATA_PATH = resolve(CWD, 'types/src/metadata.json')
const ENDPOINT = 'http://127.0.0.1:9944/'
const ENDPOINT = 'http://127.0.0.1:9944'

let nodeProcess

Expand Down Expand Up @@ -102,20 +102,34 @@ function getCurrentMetadata() {
return JSON.parse(readFileSync(METADATA_PATH, 'utf8'))
}

function fetchMetadata() {
function fetchMetadata(retryTimes = 3, retryDelaySecond = 5) {
logStep('Fetching metadata from the node...')
return new Promise((resolve, reject) => {
exec(
`curl -H "Content-Type: application/json" -d \'{"id":"1","jsonrpc":"2.0","method":"state_getMetadata","params":[]}\' ${ENDPOINT}`,
(error, stdout) => {
if (error) {
reject(error)
return
const fetchAttempt = attemptsLeft => {
exec(
`curl -H "Content-Type: application/json" -d \'{"id":"1","jsonrpc":"2.0","method":"state_getMetadata","params":[]}\' ${ENDPOINT}`,
(error, stdout) => {
if (error) {
if (attemptsLeft > 0) {
console.log(
`Fetch attempt failed. Retrying in ${retryDelaySecond} seconds... (${attemptsLeft} attempts left)`
)
setTimeout(
() => fetchAttempt(attemptsLeft - 1),
retryDelaySecond * 1000
)
} else {
reject(error)
}
return
}

resolve(JSON.parse(stdout.toString()))
}
)
}

resolve(JSON.parse(stdout.toString()))
}
)
fetchAttempt(retryTimes)
})
}

Expand All @@ -136,7 +150,7 @@ async function generateNewTypes() {

async function main() {
runTangleNode()
await sleep(10)
await sleep(15)

const [metadataFromNode, currentMetadata] = await Promise.all([
fetchMetadata(),
Expand All @@ -162,6 +176,11 @@ process.on('SIGTERM', () => {
process.exit()
})

process.on('exit', () => {
stopTangleNode()
process.exit()
})

main()
.then(() => process.exit(0))
.catch(error => {
Expand Down
65 changes: 10 additions & 55 deletions types/src/interfaces/augment-api-consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import '@polkadot/api-base/types/consts';

import type { ApiTypes, AugmentedConst } from '@polkadot/api-base/types';
import type { BTreeMap, Bytes, Option, U256, U8aFixed, Vec, bool, u128, u16, u32, u64, u8 } from '@polkadot/types-codec';
import type { Codec, ITuple } from '@polkadot/types-codec/types';
import type { AccountId32, H160, Perbill, Permill } from '@polkadot/types/interfaces/runtime';
import type { FrameSupportPalletId, FrameSystemLimitsBlockLength, FrameSystemLimitsBlockWeights, SpVersionRuntimeVersion, SpWeightsRuntimeDbWeight, SpWeightsWeightV2Weight, StagingXcmV4AssetAssetId } from '@polkadot/types/lookup';
import type { Bytes, Option, U8aFixed, Vec, bool, u128, u16, u32, u64, u8 } from '@polkadot/types-codec';
import type { Codec } from '@polkadot/types-codec/types';
import type { Perbill, Permill } from '@polkadot/types/interfaces/runtime';
import type { FrameSupportPalletId, FrameSystemLimitsBlockLength, FrameSystemLimitsBlockWeights, SpVersionRuntimeVersion, SpWeightsRuntimeDbWeight, SpWeightsWeightV2Weight } from '@polkadot/types/lookup';

export type __AugmentedConst<ApiType extends ApiTypes> = AugmentedConst<ApiType>;

Expand Down Expand Up @@ -152,10 +152,14 @@ declare module '@polkadot/api-base/types/consts' {
/**
* The maximum number of locks that should exist on an account.
* Not strictly enforced, but used for weight estimation.
*
* Use of locks is deprecated in favour of freezes. See `https://github.com/paritytech/substrate/pull/12951/`
**/
maxLocks: u32 & AugmentedConst<ApiType>;
/**
* The maximum number of named reserves that can exist on an account.
*
* Use of reserves is deprecated in favour of holds. See `https://github.com/paritytech/substrate/pull/12951/`
**/
maxReserves: u32 & AugmentedConst<ApiType>;
/**
Expand Down Expand Up @@ -365,18 +369,10 @@ declare module '@polkadot/api-base/types/consts' {
* this value.
**/
signedMaxWeight: SpWeightsWeightV2Weight & AugmentedConst<ApiType>;
/**
* Duration of the signed phase.
**/
signedPhase: u64 & AugmentedConst<ApiType>;
/**
* Base reward for a signed solution
**/
signedRewardBase: u128 & AugmentedConst<ApiType>;
/**
* Duration of the unsigned phase.
**/
unsignedPhase: u64 & AugmentedConst<ApiType>;
/**
* Generic const
**/
Expand Down Expand Up @@ -479,7 +475,7 @@ declare module '@polkadot/api-base/types/consts' {
**/
byteDeposit: u128 & AugmentedConst<ApiType>;
/**
* Maxmimum number of registrars allowed in the system. Needed to bound the complexity
* Maximum number of registrars allowed in the system. Needed to bound the complexity
* of, e.g., updating judgements.
**/
maxRegistrars: u32 & AugmentedConst<ApiType>;
Expand Down Expand Up @@ -872,34 +868,6 @@ declare module '@polkadot/api-base/types/consts' {
**/
[key: string]: Codec;
};
sygmaBridge: {
/**
* EIP712 Verifying contract address
* This is used in EIP712 typed data domain
**/
destVerifyingContractAddress: H160 & AugmentedConst<ApiType>;
/**
* Pallet ChainID
* This is used in EIP712 typed data domain
**/
eip712ChainID: U256 & AugmentedConst<ApiType>;
/**
* Fee reserve account
**/
feeReserveAccount: AccountId32 & AugmentedConst<ApiType>;
/**
* AssetId and ResourceId pairs
**/
resourcePairs: Vec<ITuple<[StagingXcmV4AssetAssetId, U8aFixed]>> & AugmentedConst<ApiType>;
/**
* Bridge transfer reserve accounts mapping with designated assets
**/
transferReserveAccounts: BTreeMap<StagingXcmV4AssetAssetId, AccountId32> & AugmentedConst<ApiType>;
/**
* Generic const
**/
[key: string]: Codec;
};
system: {
/**
* Maximum number of block number to block hash mappings to keep (oldest pruned first).
Expand All @@ -926,7 +894,7 @@ declare module '@polkadot/api-base/types/consts' {
**/
ss58Prefix: u16 & AugmentedConst<ApiType>;
/**
* Get the chain's current version.
* Get the chain's in-code version.
**/
version: SpVersionRuntimeVersion & AugmentedConst<ApiType>;
/**
Expand Down Expand Up @@ -998,19 +966,6 @@ declare module '@polkadot/api-base/types/consts' {
* The period during which an approved treasury spend has to be claimed.
**/
payoutPeriod: u64 & AugmentedConst<ApiType>;
/**
* Fraction of a proposal's value that should be bonded in order to place the proposal.
* An accepted proposal gets these back. A rejected proposal does not.
**/
proposalBond: Permill & AugmentedConst<ApiType>;
/**
* Maximum amount of funds that should be placed in a deposit for making a proposal.
**/
proposalBondMaximum: Option<u128> & AugmentedConst<ApiType>;
/**
* Minimum amount of funds that should be placed in a deposit for making a proposal.
**/
proposalBondMinimum: u128 & AugmentedConst<ApiType>;
/**
* Period between successive spends.
**/
Expand Down
Loading

0 comments on commit 27f174c

Please sign in to comment.