Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to types bundle #4011

Merged
merged 39 commits into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
f915972
support ethereum addresses
joelamouche Nov 3, 2020
df6c191
corrections
joelamouche Nov 3, 2020
46057dd
add standalone url and ethereum identicons
joelamouche Nov 3, 2020
fcefb90
add moonbeam config
joelamouche Nov 3, 2020
e5d9908
added changes from the old pr
joelamouche Nov 3, 2020
9707a48
add new config
joelamouche Nov 4, 2020
1725bff
added dummy rpc method declarations for eth methods
joelamouche Nov 4, 2020
3821ee0
wip fix address add modal
joelamouche Nov 4, 2020
173525d
support ethereum addresses
joelamouche Nov 3, 2020
d959ad0
corrections
joelamouche Nov 3, 2020
4d3863e
add standalone url and ethereum identicons
joelamouche Nov 3, 2020
94dafe6
add moonbeam config
joelamouche Nov 3, 2020
5bda4df
added changes from the old pr
joelamouche Nov 3, 2020
379923a
add new config
joelamouche Nov 4, 2020
ab9a0e1
added dummy rpc method declarations for eth methods
joelamouche Nov 4, 2020
05f0b5a
wip fix address add modal
joelamouche Nov 4, 2020
8f3ce13
ok
joelamouche Nov 4, 2020
c60a567
wip repair app with new keyring
joelamouche Nov 4, 2020
66f695f
use isDevelopement false for ethereum
joelamouche Nov 4, 2020
267dac3
lint
joelamouche Nov 4, 2020
4eaf8e7
more formatng
joelamouche Nov 4, 2020
b41a9c8
eth addresses by default for account creation
joelamouche Nov 4, 2020
6ac97a6
sync with parity master
joelamouche Nov 6, 2020
31a3875
Merge branch 'master' into node-moonbeam-integration-2
joelamouche Nov 6, 2020
ee630e6
added many more types to support moonbeam
joelamouche Nov 6, 2020
61552bf
added color
joelamouche Nov 9, 2020
6fc041a
add h160 to types and components
joelamouche Nov 9, 2020
e618105
add rpc methods to app-config
joelamouche Nov 10, 2020
cdea06d
sync with master #Merge branch 'master' into node-moonbeam-integration-2
joelamouche Nov 10, 2020
da71df3
lint
joelamouche Nov 10, 2020
16e94a8
polish
joelamouche Nov 10, 2020
7e2a535
Update packages/react-params/src/initValue.ts
joelamouche Nov 10, 2020
706f031
Apply suggestions from code review
joelamouche Nov 10, 2020
58ca9c8
mobe to typesBundle
joelamouche Nov 10, 2020
4251a94
sync with master
joelamouche Nov 11, 2020
712af03
added right type for types declaration
joelamouche Nov 11, 2020
8d56f39
lint
joelamouche Nov 11, 2020
5dc0ff5
sync with master
joelamouche Dec 4, 2020
5de8089
corrected type and removed moobeam specs
joelamouche Dec 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/apps-config/src/api/bundle/spec/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

import acala from './acala';
import laminar from './laminar';
import moonbeam from './moonbeam';

export default {
acala,
laminar,
mandala: acala
mandala: acala,
'moonbase-alphanet': moonbeam,
'moonbeam-standalone': moonbeam,
'node-moonbeam': moonbeam,
moonbeam
};
79 changes: 79 additions & 0 deletions packages/apps-config/src/api/bundle/spec/moonbeam.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright 2017-2020 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { OverrideBundleDefinition } from '@polkadot/types/types';

// structs need to be in order
/* eslint-disable sort-keys */

export default {
Copy link
Member

@jacogr jacogr Nov 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format is slightly different here, and probably the issue.

Here is an example,

export default [
  {
    // lowest version it applies to, highest version it applies to
    minmax: [0, undefined],
    // as per normal
    types: { ... }
  }
]

This allos you to manage multiples, see eg. https://github.com/polkadot-js/api/blob/master/packages/types-known/src/spec/kusama.ts where it is done for Kusama

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

However, doesn't that mean that the laminar and acala files use the wrong type (OverrideBundleDefinition)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like using OverrideVersionedType[] like in the example you provided doesn't conform to the type for Api.create of react-api

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be slightly different, honestly would need to look at what it does under the hood. Too many type options.

(I have been meaning to move all types across for all chains, Acala added the required support into the UI specifically since they had upgrades lines up)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacogr have you had the occasion to look? Should I try again?

Copy link
Member

@jacogr jacogr Dec 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should just work as defined here.

You do OverrideVersionedType[] which aligns with types-known, as first used.

When passed to the API, it expects typesBundle: OverrideBundleType which is of this form -

typesBundle: {
  spec: {
    moonbeam: {
      rpc?: ... // not sure this is used, don't worry about it now, but if we have a bundle can try
      types: OverrideVersionedType[]
    }
  }
}

The api-react should take the stuff defined and just put it in that format.

Copy link
Member

@jacogr jacogr Dec 4, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so what you should export is -

export default {
  types: OverrideVersionedType[]
};

aka a OverrideBundleDefinition which looks like -

export interface OverrideBundleDefinition {
    alias?: Record<string, OverrideModuleType>;
    rpc?: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>;
    types?: OverrideVersionedType[];
}

TL;DR Seems like you are just missing the top-level types: key containing the array.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Like I said once the types is in, we can attempt to move the RPCs as well - not 100% sure the API uses it atm, the intent is there - if it doesn't can fix)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the help. Should be ready now!

Like I said once the types is in, we can attempt to move the RPCs as well

Not too hot on adding features that aren't needed explicitly but I can add that as well if you feel this is important

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm sure that stuff is going to break and it is more for my benefit ... so I'll ply with that and see what breaks horribly. However, will get you to review once ready. (Not promising in the next couple of days, but having seen that again makes me want to get it going)

AccountId: 'EthereumAccountId',
Address: 'AccountId',
Balance: 'u128',
RefCount: 'u8',
LookupSource: 'AccountId',
Account: {
nonce: 'U256',
balance: 'u128'
},
TransactionCondition: {
_enum: {
block: 'u64',
time: 'u64'
}
},
Transaction: {
action: 'String',
block_hash: 'Option<H256>',
block_number: 'Option<U256>',
chain_id: 'Option<u64>',
condition: 'Option<TransactionCondition>',
creates: 'Option<H160>',
from: 'H160',
gas: 'U256',
gas_price: 'U256',
gas_limit: 'u64',
hash: 'H256',
input: 'Bytes',
nonce: 'U256',
public_key: 'Option<H512>',
r: 'U256',
raw: 'Bytes',
s: 'U256',
signature: 'Signature',
standard_v: 'U256',
to: 'Option<H160>',
transaction_index: 'Option<U256>',
v: 'U256',
value: 'U256'
},
Signature: {
v: 'u64',
r: 'H256',
s: 'H256'
},
TransactionStatus: {
transaction_hash: 'H256',
transaction_index: 'u32',
from: 'H160',
to: 'Option<H160>',
contract_address: 'Option<H160>',
logs: 'Vec<Log>',
logs_bloom: 'Bloom'
},
Receipt: {
transaction_hash: 'Option<H256>',
transaction_index: 'Option<U256>',
block_hash: 'Option<H256>',
from: 'Option<H160>',
to: 'Option<H160>',
block_number: 'Option<U256>',
cumulative_gas_used: 'U256',
gas_used: 'Option<U256>',
contract_address: 'Option<H160>',
logs: 'Vec<Log>',
state_root: 'Option<H256>',
logs_bloom: 'H2048',
status_code: 'Option<U64>'
}
} as OverrideBundleDefinition;
176 changes: 130 additions & 46 deletions packages/apps-config/src/api/rpc/moonbeam.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,149 @@
// Copyright 2017-2020 @polkadot/apps-config authors & contributors
// SPDX-License-Identifier: Apache-2.0

import { DefinitionRpc, DefinitionRpcParam } from '@polkadot/types/types';
import { DefinitionRpc, DefinitionRpcParam } from "@polkadot/types/types";

export default function (): Record<string, Record<string, DefinitionRpc>> {
function generateDescription (description:string, returnType:string, params:DefinitionRpcParam[] = []):DefinitionRpc {
export default function(): Record<string, Record<string, DefinitionRpc>> {
function generateDescription(
description: string,
returnType: string,
params: DefinitionRpcParam[] = []
): DefinitionRpc {
return {
description,
params,
type: returnType
};
}

const numberParam: DefinitionRpcParam = { isOptional: true, name: 'number', type: 'BlockNumber' };
const hashParam: DefinitionRpcParam = { name: 'hash', type: 'H256' };
const reqParam: DefinitionRpcParam = { name: 'request', type: 'CallRequest' };
const blockParam: DefinitionRpcParam = { name: 'block', type: 'BlockNumber' };
const addressParam: DefinitionRpcParam = { name: 'address', type: 'H160' };
const indexParam: DefinitionRpcParam = { name: 'index', type: 'U256' };
const numberParam: DefinitionRpcParam = { isOptional: true, name: "number", type: "BlockNumber" };
const hashParam: DefinitionRpcParam = { name: "hash", type: "H256" };
const reqParam: DefinitionRpcParam = { name: "request", type: "CallRequest" };
const blockParam: DefinitionRpcParam = { name: "block", type: "BlockNumber" };
const addressParam: DefinitionRpcParam = { name: "address", type: "H160" };
const indexParam: DefinitionRpcParam = { name: "index", type: "U256" };

return {
eth: {
accounts: generateDescription('Returns accounts list.', 'Vec<H160>'),
blockNumber: generateDescription('Returns balance of the given account.', 'U256'),
call: generateDescription('Call contract, returning the output data.', 'Bytes', [reqParam, numberParam]),
chainId: generateDescription('Returns the chain ID used for transaction signing at the current best block. None is returned if not available.', 'U64'),
coinbase: generateDescription('Returns block author.', 'H160'),
estimateGas: generateDescription('Estimate gas needed for execution of given contract.', 'U256', [reqParam, numberParam]),
gasPrice: generateDescription('Returns current gas_price.', 'U256'),
getBalance: generateDescription('Returns balance of the given account.', 'U256', [addressParam, numberParam]),
getBlockByHash: generateDescription('Returns block with given hash.', 'RichBlock', [hashParam, { isOptional: true, name: 'full', type: 'bool' }]),
getBlockByNumber: generateDescription('Returns block with given number.', 'RichBlock', [blockParam, { isOptional: true, name: 'full', type: 'bool' }]),
getBlockTransactionCountByHash: generateDescription('Returns the number of transactions in a block with given hash.', 'U256', [hashParam]),
getBlockTransactionCountByNumber: generateDescription('Returns the number of transactions in a block with given block number.', 'U256', [blockParam]),
getCode: generateDescription('Returns the code at given address at given time (block number).', 'Bytes', [addressParam, numberParam]),
getLogs: generateDescription('Returns logs matching given filter object.', 'Vec<Log>', [{ name: 'filter', type: 'Filter' }]),
getStorageAt: generateDescription('Returns content of the storage at given address.', 'H256', [addressParam, indexParam, numberParam]),
getTransactionByBlockHashAndIndex: generateDescription('Returns transaction at given block hash and index.', 'Transaction', [hashParam, indexParam]),
getTransactionByBlockNumberAndIndex: generateDescription('Returns transaction by given block number and index.', 'Transaction', [numberParam, indexParam]),
getTransactionByHash: generateDescription('Get transaction by its hash.', 'Transaction', [hashParam]),
getTransactionCount: generateDescription('Returns the number of transactions sent from given address at given time (block number).', 'U256', [hashParam, numberParam]),
getTransactionReceipt: generateDescription('Returns transaction receipt by transaction hash.', 'Receipt', [hashParam]),
getUncleByBlockHashAndIndex: generateDescription('Returns an uncles at given block and index.', 'RichBlock', [hashParam, indexParam]),
getUncleByBlockNumberAndIndex: generateDescription('Returns an uncles at given block and index.', 'RichBlock', [numberParam, indexParam]),
getUncleCountByBlockHash: generateDescription('Returns the number of uncles in a block with given hash.', 'U256', [hashParam]),
getUncleCountByBlockNumber: generateDescription('Returns the number of uncles in a block with given block number.', 'U256', [numberParam]),
getWork: generateDescription('Returns the hash of the current block, the seedHash, and the boundary condition to be met.', 'Work'),
hashrate: generateDescription('Returns the number of hashes per second that the node is mining with.', 'U256'),
mining: generateDescription('Returns true if client is actively mining new blocks.', 'bool'),
protocolVersion: generateDescription('Returns protocol version encoded as a string (quotes are necessary).', 'u64'),
sendRawTransaction: generateDescription('Sends signed transaction, returning its hash.', 'BoxFuture<H256>', [{ name: 'bytes', type: 'Bytes' }]),
submitHashrate: generateDescription('Used for submitting mining hashrate.', 'bool', [indexParam, hashParam]),
submitWork: generateDescription('Used for submitting a proof-of-work solution.', 'bool', [{ name: '_', type: 'H64' }, { name: '_', type: 'H256' }, { name: '_', type: 'H256' }]),
subscribe: generateDescription('Subscribe to Eth subscription.', '', [{ name: '_metadata', type: 'Self::Metadata' }, { name: 'subscriber', type: 'Subscriber<PubSubResult>' }, { name: 'kind', type: 'Kind' }, { isOptional: true, name: 'params', type: 'Params' }]),
syncing: generateDescription('Returns an object with data about the sync status or false. (wtf?)', 'SyncStatus'),
unsubscribe: generateDescription('nsubscribe from existing Eth subscription.', '', [{ name: '_metadata', type: 'Self::Metadata' }, { name: 'subscription_id', type: 'Self::SubscriptionId' }])
accounts: generateDescription("Returns accounts list.", "Vec<H160>"),
blockNumber: generateDescription("Returns balance of the given account.", "U256"),
call: generateDescription("Call contract, returning the output data.", "Bytes", [reqParam, numberParam]),
chainId: generateDescription(
"Returns the chain ID used for transaction signing at the current best block. None is returned if not available.",
"U64"
),
coinbase: generateDescription("Returns block author.", "H160"),
estimateGas: generateDescription("Estimate gas needed for execution of given contract.", "U256", [
reqParam,
numberParam
]),
gasPrice: generateDescription("Returns current gas_price.", "U256"),
getBalance: generateDescription("Returns balance of the given account.", "U256", [addressParam, numberParam]),
getBlockByHash: generateDescription("Returns block with given hash.", "RichBlock", [
hashParam,
{ isOptional: true, name: "full", type: "bool" }
]),
getBlockByNumber: generateDescription("Returns block with given number.", "RichBlock", [
blockParam,
{ isOptional: true, name: "full", type: "bool" }
]),
getBlockTransactionCountByHash: generateDescription(
"Returns the number of transactions in a block with given hash.",
"U256",
[hashParam]
),
getBlockTransactionCountByNumber: generateDescription(
"Returns the number of transactions in a block with given block number.",
"U256",
[blockParam]
),
getCode: generateDescription("Returns the code at given address at given time (block number).", "Bytes", [
addressParam,
numberParam
]),
getLogs: generateDescription("Returns logs matching given filter object.", "Vec<Log>", [
{ name: "filter", type: "Filter" }
]),
getStorageAt: generateDescription("Returns content of the storage at given address.", "H256", [
addressParam,
indexParam,
numberParam
]),
getTransactionByBlockHashAndIndex: generateDescription(
"Returns transaction at given block hash and index.",
"Transaction",
[hashParam, indexParam]
),
getTransactionByBlockNumberAndIndex: generateDescription(
"Returns transaction by given block number and index.",
"Transaction",
[numberParam, indexParam]
),
getTransactionByHash: generateDescription("Get transaction by its hash.", "Transaction", [hashParam]),
getTransactionCount: generateDescription(
"Returns the number of transactions sent from given address at given time (block number).",
"U256",
[hashParam, numberParam]
),
getTransactionReceipt: generateDescription("Returns transaction receipt by transaction hash.", "Receipt", [
hashParam
]),
getUncleByBlockHashAndIndex: generateDescription("Returns an uncles at given block and index.", "RichBlock", [
hashParam,
indexParam
]),
getUncleByBlockNumberAndIndex: generateDescription("Returns an uncles at given block and index.", "RichBlock", [
numberParam,
indexParam
]),
getUncleCountByBlockHash: generateDescription(
"Returns the number of uncles in a block with given hash.",
"U256",
[hashParam]
),
getUncleCountByBlockNumber: generateDescription(
"Returns the number of uncles in a block with given block number.",
"U256",
[numberParam]
),
getWork: generateDescription(
"Returns the hash of the current block, the seedHash, and the boundary condition to be met.",
"Work"
),
hashrate: generateDescription("Returns the number of hashes per second that the node is mining with.", "U256"),
mining: generateDescription("Returns true if client is actively mining new blocks.", "bool"),
protocolVersion: generateDescription(
"Returns protocol version encoded as a string (quotes are necessary).",
"u64"
),
sendRawTransaction: generateDescription("Sends signed transaction, returning its hash.", "BoxFuture<H256>", [
{ name: "bytes", type: "Bytes" }
]),
submitHashrate: generateDescription("Used for submitting mining hashrate.", "bool", [indexParam, hashParam]),
submitWork: generateDescription("Used for submitting a proof-of-work solution.", "bool", [
{ name: "_", type: "H64" },
{ name: "_", type: "H256" },
{ name: "_", type: "H256" }
]),
subscribe: generateDescription("Subscribe to Eth subscription.", "", [
{ name: "_metadata", type: "Self::Metadata" },
{ name: "subscriber", type: "Subscriber<PubSubResult>" },
{ name: "kind", type: "Kind" },
{ isOptional: true, name: "params", type: "Params" }
]),
syncing: generateDescription("Returns an object with data about the sync status or false. (wtf?)", "SyncStatus"),
unsubscribe: generateDescription("nsubscribe from existing Eth subscription.", "", [
{ name: "_metadata", type: "Self::Metadata" },
{ name: "subscription_id", type: "Self::SubscriptionId" }
])
},
net: {
listening: generateDescription('Returns true if client is actively listening for network connections. Otherwise false.', 'bool'),
peerCount: generateDescription('Returns number of peers connected to node.', 'String'),
version: generateDescription('Returns protocol version.', 'String')
listening: generateDescription(
"Returns true if client is actively listening for network connections. Otherwise false.",
"bool"
),
peerCount: generateDescription("Returns number of peers connected to node.", "String"),
version: generateDescription("Returns protocol version.", "String")
}
};
}