diff --git a/.editorconfig b/.editorconfig index 8eba899188..b242724b7c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -29,7 +29,6 @@ max_line_length=100 [*.json] indent_style=space indent_size=2 -max_line_length=100 [*.md] trim_trailing_whitespace=false diff --git a/polkadot-js/alphanet-types.json b/polkadot-js/alphanet-types.json index 40ba01d70a..2e8c75d325 100644 --- a/polkadot-js/alphanet-types.json +++ b/polkadot-js/alphanet-types.json @@ -8,18 +8,96 @@ "nonce": "U256", "balance": "u128" }, + "TransactionCondition": { + "_enum": { + "block": "u64", + "time": "u64" + } + }, "Transaction": { + "block_hash": "Option", + "block_number": "Option", + "chain_id": "Option", + "condition": "Option", + "creates": "Option", + "from": "H160", + "gas": "U256", + "gas_price": "U256", + "hash": "H256", + "input": "Bytes", "nonce": "U256", - "action": "String", - "gas_price": "u64", - "gas_limit": "u64", - "value": "U256", - "input": "Vec", - "signature": "Signature" - }, - "Signature": { - "v": "u64", - "r": "H256", - "s": "H256" + "public_key": "Option", + "r": "U256", + "raw": "Bytes", + "s": "U256", + "standard_v": "U256", + "to": "Option", + "transaction_index": "Option", + "v": "U256", + "value": "U256" + }, + "TransactionStatus": { + "transaction_hash": "H256", + "transaction_index": "u32", + "from": "H160", + "to": "Option", + "contract_address": "Option", + "logs": "Vec", + "logs_bloom": "Bloom" + }, + "Receipt": { + "transaction_hash": "Option", + "transaction_index": "Option", + "block_hash": "Option", + "from": "Option", + "to": "Option", + "block_number": "Option", + "cumulative_gas_used": "U256", + "gas_used": "Option", + "contract_address": "Option", + "logs": "Vec", + "state_root": "Option", + "logs_bloom": "H2048", + "status_code": "Option" + }, + "ExitReason": { + "_enum": { + "Succeed": "ExitSucceed", + "Error": "ExitError", + "Revert": "ExitRevert", + "Fatal": "ExitFatal" + } + }, + "ExitSucceed": { + "_enum": ["Stopped", "Returned", "Suicided"] + }, + "ExitError": { + "_enum": [ + "StackUnderflow", + "StackOverflow", + "InvalidJump", + "InvalidRange", + "DesignatedInvalid", + "CallTooDeep", + "CreateCollision", + "CreateContractLimit", + "OutOfOffset", + "OutOfGas", + "OutOfFund", + "PCUnderflow", + "CreateEmpty", + "Other(Cow<'static, str>)" + ] + }, + "ExitRevert": { + "_enum": ["Reverted"] + }, + "ExitFatal": { + "_enum": [ + "NotSupported", + "UnhandledInterrupt", + "CallErrorAsFatal(ExitError)", + "Other(Cow<'static, str>)" + ] } } diff --git a/polkadot-js/frontier-rpc-types.json b/polkadot-js/frontier-rpc-types.json new file mode 100644 index 0000000000..5d03efe31f --- /dev/null +++ b/polkadot-js/frontier-rpc-types.json @@ -0,0 +1,245 @@ +{ + "eth": { + "accounts": { + "description": "Returns accounts list.", + "params": [], + "type": "Vec" + }, + "blockNumber": { + "description": "Returns balance of the given account.", + "params": [], + "type": "U256" + }, + "call": { + "description": "Call contract, returning the output data.", + "params": [ + { "name": "request", "type": "CallRequest" }, + { "isOptional": true, "name": "number", "type": "BlockNumber" } + ], + "type": "Bytes" + }, + "chainId": { + "description": "Returns the chain ID used for transaction signing at the current best block. None is returned if not available.", + "params": [], + "type": "U64" + }, + "coinbase": { + "description": "Returns block author.", + "params": [], + "type": "H160" + }, + "estimateGas": { + "description": "Estimate gas needed for execution of given contract.", + "params": [ + { "name": "request", "type": "CallRequest" }, + { "isOptional": true, "name": "number", "type": "BlockNumber" } + ], + "type": "U256" + }, + "gasPrice": { + "description": "Returns current gas_price.", + "params": [], + "type": "U256" + }, + "getBalance": { + "description": "Returns balance of the given account.", + "params": [ + { "name": "address", "type": "H160" }, + { "isOptional": true, "name": "number", "type": "BlockNumber" } + ], + "type": "U256" + }, + "getBlockByHash": { + "description": "Returns block with given hash.", + "params": [ + { "name": "hash", "type": "H256" }, + { "isOptional": true, "name": "full", "type": "bool" } + ], + "type": "RichBlock" + }, + "getBlockByNumber": { + "description": "Returns block with given number.", + "params": [ + { "name": "block", "type": "BlockNumber" }, + { "isOptional": true, "name": "full", "type": "bool" } + ], + "type": "RichBlock" + }, + "getBlockTransactionCountByHash": { + "description": "Returns the number of transactions in a block with given hash.", + "params": [{ "name": "hash", "type": "H256" }], + "type": "U256" + }, + "getBlockTransactionCountByNumber": { + "description": "Returns the number of transactions in a block with given block number.", + "params": [{ "name": "block", "type": "BlockNumber" }], + "type": "U256" + }, + "getCode": { + "description": "Returns the code at given address at given time (block number).", + "params": [ + { "name": "address", "type": "H160" }, + { "isOptional": true, "name": "number", "type": "BlockNumber" } + ], + "type": "Bytes" + }, + "getLogs": { + "description": "Returns logs matching given filter object.", + "params": [{ "name": "filter", "type": "Filter" }], + "type": "Vec" + }, + "getStorageAt": { + "description": "Returns content of the storage at given address.", + "params": [ + { "name": "address", "type": "H160" }, + { "name": "index", "type": "U256" }, + { "isOptional": true, "name": "number", "type": "BlockNumber" } + ], + "type": "H256" + }, + "getTransactionByBlockHashAndIndex": { + "description": "Returns transaction at given block hash and index.", + "params": [ + { "name": "hash", "type": "H256" }, + { "name": "index", "type": "U256" } + ], + "type": "Transaction" + }, + "getTransactionByBlockNumberAndIndex": { + "description": "Returns transaction by given block number and index.", + "params": [ + { "isOptional": true, "name": "number", "type": "BlockNumber" }, + { "name": "index", "type": "U256" } + ], + "type": "Transaction" + }, + "getTransactionByHash": { + "description": "Get transaction by its hash.", + "params": [{ "name": "hash", "type": "H256" }], + "type": "Transaction" + }, + "getTransactionCount": { + "description": "Returns the number of transactions sent from given address at given time (block number).", + "params": [ + { "name": "hash", "type": "H256" }, + { "isOptional": true, "name": "number", "type": "BlockNumber" } + ], + "type": "U256" + }, + "getTransactionReceipt": { + "description": "Returns transaction receipt by transaction hash.", + "params": [{ "name": "hash", "type": "H256" }], + "type": "Receipt" + }, + "getUncleByBlockHashAndIndex": { + "description": "Returns an uncles at given block and index.", + "params": [ + { "name": "hash", "type": "H256" }, + { "name": "index", "type": "U256" } + ], + "type": "RichBlock" + }, + "getUncleByBlockNumberAndIndex": { + "description": "Returns an uncles at given block and index.", + "params": [ + { "isOptional": true, "name": "number", "type": "BlockNumber" }, + { "name": "index", "type": "U256" } + ], + "type": "RichBlock" + }, + "getUncleCountByBlockHash": { + "description": "Returns the number of uncles in a block with given hash.", + "params": [{ "name": "hash", "type": "H256" }], + "type": "U256" + }, + "getUncleCountByBlockNumber": { + "description": "Returns the number of uncles in a block with given block number.", + "params": [ + { "isOptional": true, "name": "number", "type": "BlockNumber" } + ], + "type": "U256" + }, + "getWork": { + "description": "Returns the hash of the current block, the seedHash, and the boundary condition to be met.", + "params": [], + "type": "Work" + }, + "hashrate": { + "description": "Returns the number of hashes per second that the node is mining with.", + "params": [], + "type": "U256" + }, + "mining": { + "description": "Returns true if client is actively mining new blocks.", + "params": [], + "type": "bool" + }, + "protocolVersion": { + "description": "Returns protocol version encoded as a string (quotes are necessary).", + "params": [], + "type": "u64" + }, + "sendRawTransaction": { + "description": "Sends signed transaction, returning its hash.", + "params": [{ "name": "bytes", "type": "Bytes" }], + "type": "BoxFuture" + }, + "submitHashrate": { + "description": "Used for submitting mining hashrate.", + "params": [ + { "name": "index", "type": "U256" }, + { "name": "hash", "type": "H256" } + ], + "type": "bool" + }, + "submitWork": { + "description": "Used for submitting a proof-of-work solution.", + "params": [ + { "name": "_", "type": "H64" }, + { "name": "_", "type": "H256" }, + { "name": "_", "type": "H256" } + ], + "type": "bool" + }, + "subscribe": { + "description": "Subscribe to Eth subscription.", + "params": [ + { "name": "_metadata", "type": "Self::Metadata" }, + { "name": "subscriber", "type": "Subscriber" }, + { "name": "kind", "type": "Kind" }, + { "isOptional": true, "name": "params", "type": "Params" } + ], + "type": "" + }, + "syncing": { + "description": "Returns an object with data about the sync status or false. (wtf?)", + "params": [], + "type": "SyncStatus" + }, + "unsubscribe": { + "description": "nsubscribe from existing Eth subscription.", + "params": [ + { "name": "_metadata", "type": "Self::Metadata" }, + { "name": "subscription_id", "type": "Self::SubscriptionId" } + ], + "type": "" + } + }, + "net": { + "listening": { + "description": "Returns true if client is actively listening for network connections. Otherwise false.", + "params": [], + "type": "bool" + }, + "peerCount": { + "description": "Returns number of peers connected to node.", + "params": [], + "type": "String" + }, + "version": { + "description": "Returns protocol version.", + "params": [], + "type": "String" + } + } +} diff --git a/polkadot-js/standalone-types.json b/polkadot-js/standalone-types.json index 40ba01d70a..ea2be4832f 100644 --- a/polkadot-js/standalone-types.json +++ b/polkadot-js/standalone-types.json @@ -8,18 +8,96 @@ "nonce": "U256", "balance": "u128" }, + "TransactionCondition": { + "_enum": { + "block": "u64", + "time": "u64" + } + }, "Transaction": { + "block_hash": "Option", + "block_number": "Option", + "chain_id": "Option", + "condition": "Option", + "creates": "Option", + "from": "H160", + "gas": "U256", + "gas_price": "U256", + "hash": "H256", + "input": "Bytes", "nonce": "U256", - "action": "String", - "gas_price": "u64", - "gas_limit": "u64", - "value": "U256", - "input": "Vec", - "signature": "Signature" - }, - "Signature": { - "v": "u64", - "r": "H256", - "s": "H256" + "public_key": "Option", + "r": "U256", + "raw": "Bytes", + "s": "U256", + "standard_v": "U256", + "to": "Option", + "transaction_index": "Option", + "v": "U256", + "value": "U256" + }, + "TransactionStatus": { + "transaction_hash": "H256", + "transaction_index": "u32", + "from": "H160", + "to": "Option", + "contract_address": "Option", + "logs": "Vec", + "logs_bloom": "Bloom" + }, + "Receipt": { + "transaction_hash": "Option", + "transaction_index": "Option", + "block_hash": "Option", + "from": "Option", + "to": "Option", + "block_number": "Option", + "cumulative_gas_used": "U256", + "gas_used": "Option", + "contract_address": "Option", + "logs": "Vec", + "state_root": "Option", + "logs_bloom": "H2048", + "status_code": "Option" + }, + "ExitReason": { + "_enum": { + "Succeed": "ExitSucceed", + "Error": "ExitError", + "Revert": "ExitRevert", + "verFatal": "ExitFatal" + } + }, + "ExitSucceed": { + "_enum": ["Stopped", "Returned", "Suicided"] + }, + "ExitError": { + "_enum": [ + "StackUnderflow", + "StackOverflow", + "InvalidJump", + "InvalidRange", + "DesignatedInvalid", + "CallTooDeep", + "CreateCollision", + "CreateContractLimit", + "OutOfOffset", + "OutOfGas", + "OutOfFund", + "PCUnderflow", + "CreateEmpty", + "Other(Cow<'static, str>)" + ] + }, + "ExitRevert": { + "_enum": ["Reverted"] + }, + "ExitFatal": { + "_enum": [ + "NotSupported", + "UnhandledInterrupt", + "CallErrorAsFatal(ExitError)", + "Other(Cow<'static, str>)" + ] } } diff --git a/tools/generate-rpc-types.ts b/tools/generate-rpc-types.ts new file mode 100644 index 0000000000..7677f824bf --- /dev/null +++ b/tools/generate-rpc-types.ts @@ -0,0 +1,212 @@ +// Copyright 2017-2020 @polkadot/apps-config authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +//import { DefinitionRpc, DefinitionRpcParam } from "@polkadot/types/types"; +export declare type DefinitionTypeType = string; +export declare type DefinitionTypeEnum = + | { + _enum: DefinitionTypeType[]; + } + | { + _enum: Record; + }; +export declare type DefinitionTypeSet = { + _set: Record; +}; +export declare type DefinitionTypeStruct = + | Record + | ({ + _alias?: Record; + } & Record); +export declare type DefinitionType = + | string + | DefinitionTypeEnum + | DefinitionTypeSet + | DefinitionTypeStruct; +interface DefinitionRpcParam { + isCached?: boolean; + isHistoric?: boolean; + isOptional?: boolean; + name: string; + type: DefinitionTypeType; +} +interface DefinitionRpc { + alias?: string[]; + description: string; + endpoint?: string; + params: DefinitionRpcParam[]; + type: DefinitionTypeType; +} + +export default function rpcTypes(): Record> { + 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" }; + + return { + eth: { + accounts: generateDescription("Returns accounts list.", "Vec"), + 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", [ + { 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", + [{ 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" }, + { 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"), + }, + }; +} +console.log(JSON.stringify(rpcTypes()));