From f91597282690d8f16b5b05c098ba7f1356e310e8 Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 3 Nov 2020 14:12:19 +0100 Subject: [PATCH 01/33] support ethereum addresses --- packages/page-accounts/src/Vanity/index.tsx | 5 +++-- packages/page-accounts/src/modals/Create.tsx | 4 ++-- packages/page-addresses/src/modals/Create.tsx | 4 ++-- packages/page-settings/src/util.tsx | 4 +++- packages/page-signing/src/Verify.tsx | 1 + packages/react-api/src/Api.tsx | 3 +++ packages/react-api/src/types.ts | 1 + packages/react-components/src/util/toAddress.ts | 9 +++++++-- 8 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/page-accounts/src/Vanity/index.tsx b/packages/page-accounts/src/Vanity/index.tsx index 2e502f704f66..8d7419b9b92e 100644 --- a/packages/page-accounts/src/Vanity/index.tsx +++ b/packages/page-accounts/src/Vanity/index.tsx @@ -8,7 +8,7 @@ import { GeneratorMatches, GeneratorMatch, GeneratorResult } from '@polkadot/van import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import styled from 'styled-components'; import { Button, Dropdown, Input, Table } from '@polkadot/react-components'; -import { useIsMountedRef } from '@polkadot/react-hooks'; +import { useIsMountedRef, useApi } from '@polkadot/react-hooks'; import uiSettings from '@polkadot/ui-settings'; import generator from '@polkadot/vanitygen/generator'; import matchRegex from '@polkadot/vanitygen/regex'; @@ -45,6 +45,7 @@ const BOOL_OPTIONS = [ function VanityApp ({ className = '', onStatusChange }: Props): React.ReactElement { const { t } = useTranslation(); + const { isEthereum } = useApi(); const results = useRef([]); const runningRef = useRef(false); const mountedRef = useIsMountedRef(); @@ -211,7 +212,7 @@ function VanityApp ({ className = '', onStatusChange }: Props): React.ReactEleme help={t('Determines what cryptography will be used to create this account. Note that to validate on Polkadot, the session account must use "ed25519".')} label={t('keypair crypto type')} onChange={setType} - options={uiSettings.availableCryptos} + options={isEthereum ? uiSettings.availableCryptosEth : uiSettings.availableCryptos} /> diff --git a/packages/page-accounts/src/modals/Create.tsx b/packages/page-accounts/src/modals/Create.tsx index 06e2ad7a7287..94dc52a6044d 100644 --- a/packages/page-accounts/src/modals/Create.tsx +++ b/packages/page-accounts/src/modals/Create.tsx @@ -182,7 +182,7 @@ function createAccount (suri: string, pairType: KeypairType, { genesisHash, name function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, type: propsType }: Props): React.ReactElement { const { t } = useTranslation(); - const { api, isDevelopment } = useApi(); + const { api, isDevelopment, isEthereum } = useApi(); const [{ address, derivePath, deriveValidation, isSeedValid, pairType, seed, seedType }, setAddress] = useState(generateSeed(propsSeed, '', propsSeed ? 'raw' : 'bip', propsType)); const [isMnemonicSaved, setIsMnemonicSaved] = useState(false); const [step, setStep] = useState(1); @@ -339,7 +339,7 @@ function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, typ help={t('Determines what cryptography will be used to create this account. Note that to validate on Polkadot, the session account must use "ed25519".')} label={t('keypair crypto type')} onChange={_onChangePairType} - options={uiSettings.availableCryptos} + options={isEthereum ? uiSettings.availableCryptosEth : uiSettings.availableCryptos} tabIndex={-1} /> diff --git a/packages/page-addresses/src/modals/Create.tsx b/packages/page-addresses/src/modals/Create.tsx index a602d6592999..6bb9117017b9 100644 --- a/packages/page-addresses/src/modals/Create.tsx +++ b/packages/page-addresses/src/modals/Create.tsx @@ -27,7 +27,7 @@ interface NameState { function Create ({ onClose, onStatusChange }: Props): React.ReactElement { const { t } = useTranslation(); - const { api } = useApi(); + const { api, isEthereum } = useApi(); const [{ isNameValid, name }, setName] = useState({ isNameValid: false, name: '' }); const [{ address, addressInput, isAddressExisting, isAddressValid }, setAddress] = useState({ address: '', addressInput: '', isAddressExisting: false, isAddressValid: false, isPublicKey: false }); const info = useCall(!!address && isAddressValid && api.derive.accounts.info, [address]); @@ -45,7 +45,7 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement address = keyring.encodeAddress(publicKey); isAddressValid = keyring.isAvailable(address); - isPublicKey = publicKey.length === 32; + isPublicKey = isEthereum? publicKey.length === 20:publicKey.length === 32; if (!isAddressValid) { const old = keyring.getAddress(address); diff --git a/packages/page-settings/src/util.tsx b/packages/page-settings/src/util.tsx index 0e522b79019c..455d9b6b9aa9 100644 --- a/packages/page-settings/src/util.tsx +++ b/packages/page-settings/src/util.tsx @@ -3,6 +3,7 @@ import { Option } from '@polkadot/apps-config/settings/types'; import { SettingsStruct } from '@polkadot/ui-settings/types'; +import { useApi } from '@polkadot/react-hooks'; import React from 'react'; import { ChainImg, Dropdown, IdentityIcon } from '@polkadot/react-components'; @@ -40,6 +41,7 @@ export function createOption ({ info, isHeader, text, value }: Option, overrides } export function createIdenticon ({ info, text, value }: Option, overrides: string[] = [], override = 'empty'): Option { + const { isEthereum } = useApi(); const theme = info && overrides.includes(info) ? override as 'empty' : info as 'substrate'; @@ -60,7 +62,7 @@ export function createIdenticon ({ info, text, value }: Option, overrides: strin : ( diff --git a/packages/page-signing/src/Verify.tsx b/packages/page-signing/src/Verify.tsx index cafbbcb632a1..93caaa8e0b5c 100644 --- a/packages/page-signing/src/Verify.tsx +++ b/packages/page-signing/src/Verify.tsx @@ -66,6 +66,7 @@ function Verify ({ className = '' }: Props): React.ReactElement { const _onChangeAddress = useCallback( (accountId: string | null): void => { + console.log('TODO:H160') let publicKey: Uint8Array | null = null; try { diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 468bd65b9109..d0eff1770d94 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -162,12 +162,15 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise Date: Tue, 3 Nov 2020 15:21:26 +0100 Subject: [PATCH 02/33] corrections --- packages/page-addresses/src/modals/Create.tsx | 4 ++- .../src/IdentityIcon/index.tsx | 31 +++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/packages/page-addresses/src/modals/Create.tsx b/packages/page-addresses/src/modals/Create.tsx index 6bb9117017b9..f91a23f3eb05 100644 --- a/packages/page-addresses/src/modals/Create.tsx +++ b/packages/page-addresses/src/modals/Create.tsx @@ -45,7 +45,9 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement address = keyring.encodeAddress(publicKey); isAddressValid = keyring.isAvailable(address); - isPublicKey = isEthereum? publicKey.length === 20:publicKey.length === 32; + console.log('TODO:H160') + console.log(publicKey.length) + isPublicKey = publicKey.length === 32; if (!isAddressValid) { const old = keyring.getAddress(address); diff --git a/packages/react-components/src/IdentityIcon/index.tsx b/packages/react-components/src/IdentityIcon/index.tsx index 75832bf680ac..9344f5e3a32f 100644 --- a/packages/react-components/src/IdentityIcon/index.tsx +++ b/packages/react-components/src/IdentityIcon/index.tsx @@ -14,6 +14,8 @@ import StatusContext from '../Status/Context'; import { useTranslation } from '../translate'; import RoboHash from './RoboHash'; +import makeBlockie from 'ethereum-blockies-base64'; + interface Props { className?: string; prefix?: IdentityProps['prefix']; @@ -27,7 +29,7 @@ export function getIdentityTheme (systemName: string): 'substrate' { } function IdentityIcon ({ className = '', prefix, size = 24, theme, value }: Props): React.ReactElement { - const { systemName } = useApi(); + const { systemName, isEthereum } = useApi(); const { t } = useTranslation(); const { queueAction } = useContext(StatusContext); const thisTheme = theme || getIdentityTheme(systemName); @@ -44,18 +46,21 @@ function IdentityIcon ({ className = '', prefix, size = 24, theme, value }: Prop }), [queueAction, t] ); - - return ( - - ); + if (isEthereum){ + return + } else { + return ( + + ); + } } export default React.memo(styled(IdentityIcon)` From 46057dd6b3e666e30ef2f88bf99c360d01181fad Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 3 Nov 2020 16:30:49 +0100 Subject: [PATCH 03/33] add standalone url and ethereum identicons --- packages/react-api/src/Api.tsx | 2 +- packages/react-components/src/IdentityIcon/index.tsx | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index d0eff1770d94..082dd2c53713 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -162,7 +162,7 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise - } else { return ( ); - } } export default React.memo(styled(IdentityIcon)` From fcefb90f6d01c22ebff02ae45ea0648fd3b9dd4a Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 3 Nov 2020 18:51:54 +0100 Subject: [PATCH 04/33] add moonbeam config --- packages/apps-config/src/api/spec/index.ts | 4 ++++ packages/apps-config/src/api/spec/moonbeam.ts | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 packages/apps-config/src/api/spec/moonbeam.ts diff --git a/packages/apps-config/src/api/spec/index.ts b/packages/apps-config/src/api/spec/index.ts index fd5431478c5f..e7fd20860e7a 100644 --- a/packages/apps-config/src/api/spec/index.ts +++ b/packages/apps-config/src/api/spec/index.ts @@ -15,6 +15,7 @@ import equilibrium from './equilibrium'; import hanonycash from './hanonycash'; import kilt from './kilt'; import kulupu from './kulupu'; +import moonbeam from './moonbeam'; import nodeTemplate from './node-template'; import nodle from './nodle'; import plasm from './plasm'; @@ -42,6 +43,9 @@ export default { hanonycash, kulupu, 'mashnet-node': kilt, + 'node-moonbeam': moonbeam, + 'moonbase-alphanet': moonbeam, + 'moonbeam-standalone': moonbeam, 'node-template': nodeTemplate, 'nodle-chain': nodle, plasm, diff --git a/packages/apps-config/src/api/spec/moonbeam.ts b/packages/apps-config/src/api/spec/moonbeam.ts new file mode 100644 index 000000000000..c2c5d7a68f40 --- /dev/null +++ b/packages/apps-config/src/api/spec/moonbeam.ts @@ -0,0 +1,17 @@ +// Copyright 2017-2020 @polkadot/apps-config authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +// structs need to be in order +/* eslint-disable sort-keys */ + +export default { + Account: { + nonce: 'U256', + balance: 'U256', + }, + AccountId: 'EthereumAccountId', + Address: 'AccountId', + Balance: 'u128', + LookupSource: 'AccountId' +}; \ No newline at end of file From e5d9908a252e356b2dbcd9c5ff8c5df5075f160a Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 3 Nov 2020 18:56:34 +0100 Subject: [PATCH 05/33] added changes from the old pr --- packages/react-components/src/IdentityIcon/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-components/src/IdentityIcon/index.tsx b/packages/react-components/src/IdentityIcon/index.tsx index f6b4f26ad324..c6836193cda9 100644 --- a/packages/react-components/src/IdentityIcon/index.tsx +++ b/packages/react-components/src/IdentityIcon/index.tsx @@ -52,7 +52,7 @@ function IdentityIcon ({ className = '', prefix, size = 24, theme, value }: Prop prefix={prefix} size={size} theme={isEthereum? 'ethereum' : thisTheme as 'substrate'} - value={value.length==42? value+"000000":value} + value={value} /> ); } From 9707a488c6acb301438d688af8ecf1e5943e601d Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 4 Nov 2020 10:35:15 +0100 Subject: [PATCH 06/33] add new config --- packages/apps-config/src/api/spec/moonbeam.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/apps-config/src/api/spec/moonbeam.ts b/packages/apps-config/src/api/spec/moonbeam.ts index c2c5d7a68f40..85afae0c3d08 100644 --- a/packages/apps-config/src/api/spec/moonbeam.ts +++ b/packages/apps-config/src/api/spec/moonbeam.ts @@ -13,5 +13,6 @@ export default { AccountId: 'EthereumAccountId', Address: 'AccountId', Balance: 'u128', + RefCount: "u8", LookupSource: 'AccountId' }; \ No newline at end of file From 1725bffb3a914ce0b191bca68a9d7fa5605e75d3 Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 4 Nov 2020 11:38:14 +0100 Subject: [PATCH 07/33] added dummy rpc method declarations for eth methods --- packages/react-api/src/Api.tsx | 8 ++-- packages/react-api/src/rpcMethods.ts | 59 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 packages/react-api/src/rpcMethods.ts diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 082dd2c53713..4943ecb65f39 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -4,6 +4,8 @@ import { InjectedExtension } from '@polkadot/extension-inject/types'; import { KeyringStore } from '@polkadot/ui-keyring/types'; import { ChainProperties, ChainType } from '@polkadot/types/interfaces'; +import {DefinitionRpc} from '@polkadot/types/types' +import getRPCMethods from './rpcMethods' import { ApiProps, ApiState } from './types'; import React, { useContext, useEffect, useMemo, useState } from 'react'; @@ -121,7 +123,6 @@ async function retrieve (api: ApiPromise, injectedPromise: Promise, store: KeyringStore | undefined, types: Record>): Promise { registry.register(types); - const { injectedAccounts, properties, systemChain, systemChainType, systemName, systemVersion } = await retrieve(api, injectedPromise); const ss58Format = uiSettings.prefix === -1 ? properties.ss58Format.unwrapOr(DEFAULT_SS58).toNumber() @@ -162,7 +163,7 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise | null const provider = new WsProvider(url); const signer = new ApiSigner(queuePayload, queueSetTxStatus); const types = getDevTypes(); + const rpc:Record> = getRPCMethods(); - api = new ApiPromise({ provider, registry, signer, types, typesBundle, typesChain, typesSpec }); + api = new ApiPromise({ provider, registry, signer, types, typesBundle, typesChain, typesSpec, rpc }); api.on('connected', () => setIsApiConnected(true)); api.on('disconnected', () => setIsApiConnected(false)); diff --git a/packages/react-api/src/rpcMethods.ts b/packages/react-api/src/rpcMethods.ts new file mode 100644 index 000000000000..ab27635534b8 --- /dev/null +++ b/packages/react-api/src/rpcMethods.ts @@ -0,0 +1,59 @@ + +import {DefinitionRpc} from '@polkadot/types/types' +export default function getRPCMethods ():Record> { + let dummyDescription={ + description: 'Just a test method', + params: [ + { + name: 'index', + type: 'u64' + }, + { + name: 'at', + type: 'Hash', + isOptional: true + } + ], + type: 'Balance' + } + return { + eth: { + accounts: dummyDescription, + blockNumber: dummyDescription, + call: dummyDescription, + chainId: dummyDescription, + coinbase: dummyDescription, + estimateGas: dummyDescription, + gasPrice: dummyDescription, + getBalance: dummyDescription, + getBlockByHash: dummyDescription, + getBlockByNumber: dummyDescription, + getBlockTransactionCountByHash: dummyDescription, + getBlockTransactionCountByNumber: dummyDescription, + getCode: dummyDescription, + getLogs: dummyDescription, + getStorageAt: dummyDescription, + getTransactionByBlockHashAndIndex: dummyDescription, + getTransactionByBlockNumberAndIndex: dummyDescription, + getTransactionByHash: dummyDescription, + getTransactionCount: dummyDescription, + getTransactionReceipt: dummyDescription, + getUncleByBlockHashAndIndex: dummyDescription, + getUncleByBlockNumberAndIndex: dummyDescription, + getUncleCountByBlockHash: dummyDescription, + getUncleCountByBlockNumber: dummyDescription, + getWork: dummyDescription, + hashrate: dummyDescription, + mining: dummyDescription, + protocolVersion: dummyDescription, + sendRawTransaction: dummyDescription, + submitHashrate: dummyDescription, + submitWork: dummyDescription, + subscribe: dummyDescription, + syncing: dummyDescription, + unsubscribe: dummyDescription, + net_listening: dummyDescription, + net_peerCount: dummyDescription, + net_version: dummyDescription + }}} + \ No newline at end of file From 3821ee0b0bd8c4b3ddc0afa9878f586a4b6074bf Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 4 Nov 2020 12:56:28 +0100 Subject: [PATCH 08/33] wip fix address add modal --- packages/page-addresses/src/modals/Create.tsx | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/page-addresses/src/modals/Create.tsx b/packages/page-addresses/src/modals/Create.tsx index f91a23f3eb05..e94fb2e463ac 100644 --- a/packages/page-addresses/src/modals/Create.tsx +++ b/packages/page-addresses/src/modals/Create.tsx @@ -9,6 +9,8 @@ import React, { useCallback, useState } from 'react'; import { AddressRow, Button, Input, InputAddress, Modal } from '@polkadot/react-components'; import { useApi, useCall } from '@polkadot/react-hooks'; import keyring from '@polkadot/ui-keyring'; +import { hexToU8a } from '@polkadot/util'; +import { ethereumEncode } from '@polkadot/util-crypto'; import { useTranslation } from '../translate'; @@ -41,13 +43,19 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement let isPublicKey = false; try { - const publicKey = keyring.decodeAddress(addressInput); - - address = keyring.encodeAddress(publicKey); - isAddressValid = keyring.isAvailable(address); - console.log('TODO:H160') - console.log(publicKey.length) - isPublicKey = publicKey.length === 32; + if (isEthereum) { + const rawAddress = hexToU8a(addressInput); + + address = ethereumEncode(rawAddress); + console.log("rawaddy",rawAddress,rawAddress.length) + isPublicKey = rawAddress.length === 20; + console.log("isPublicKey",isPublicKey) + } else { + const publicKey = keyring.decodeAddress(addressInput); + + address = keyring.encodeAddress(publicKey); + isPublicKey = publicKey.length === 32; + } if (!isAddressValid) { const old = keyring.getAddress(address); @@ -64,10 +72,11 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement } catch (error) { isAddressValid = false; } + console.log("isAddressValid",isAddressValid) setAddress({ address: isAddressValid ? address : '', addressInput, isAddressExisting, isAddressValid, isPublicKey }); }, - [name] + [isEthereum, name] ); const _onChangeName = useCallback( From 173525df8eb72c31660b200f2a5deb0b20b9f6d7 Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 3 Nov 2020 14:12:19 +0100 Subject: [PATCH 09/33] support ethereum addresses --- packages/page-accounts/src/Vanity/index.tsx | 5 +++-- packages/page-accounts/src/modals/Create.tsx | 4 ++-- packages/page-addresses/src/modals/Create.tsx | 4 ++-- packages/page-settings/src/util.tsx | 4 +++- packages/page-signing/src/Verify.tsx | 1 + packages/react-api/src/Api.tsx | 3 +++ packages/react-api/src/types.ts | 1 + packages/react-components/src/util/toAddress.ts | 9 +++++++-- 8 files changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/page-accounts/src/Vanity/index.tsx b/packages/page-accounts/src/Vanity/index.tsx index 2e502f704f66..8d7419b9b92e 100644 --- a/packages/page-accounts/src/Vanity/index.tsx +++ b/packages/page-accounts/src/Vanity/index.tsx @@ -8,7 +8,7 @@ import { GeneratorMatches, GeneratorMatch, GeneratorResult } from '@polkadot/van import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import styled from 'styled-components'; import { Button, Dropdown, Input, Table } from '@polkadot/react-components'; -import { useIsMountedRef } from '@polkadot/react-hooks'; +import { useIsMountedRef, useApi } from '@polkadot/react-hooks'; import uiSettings from '@polkadot/ui-settings'; import generator from '@polkadot/vanitygen/generator'; import matchRegex from '@polkadot/vanitygen/regex'; @@ -45,6 +45,7 @@ const BOOL_OPTIONS = [ function VanityApp ({ className = '', onStatusChange }: Props): React.ReactElement { const { t } = useTranslation(); + const { isEthereum } = useApi(); const results = useRef([]); const runningRef = useRef(false); const mountedRef = useIsMountedRef(); @@ -211,7 +212,7 @@ function VanityApp ({ className = '', onStatusChange }: Props): React.ReactEleme help={t('Determines what cryptography will be used to create this account. Note that to validate on Polkadot, the session account must use "ed25519".')} label={t('keypair crypto type')} onChange={setType} - options={uiSettings.availableCryptos} + options={isEthereum ? uiSettings.availableCryptosEth : uiSettings.availableCryptos} /> diff --git a/packages/page-accounts/src/modals/Create.tsx b/packages/page-accounts/src/modals/Create.tsx index 06e2ad7a7287..94dc52a6044d 100644 --- a/packages/page-accounts/src/modals/Create.tsx +++ b/packages/page-accounts/src/modals/Create.tsx @@ -182,7 +182,7 @@ function createAccount (suri: string, pairType: KeypairType, { genesisHash, name function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, type: propsType }: Props): React.ReactElement { const { t } = useTranslation(); - const { api, isDevelopment } = useApi(); + const { api, isDevelopment, isEthereum } = useApi(); const [{ address, derivePath, deriveValidation, isSeedValid, pairType, seed, seedType }, setAddress] = useState(generateSeed(propsSeed, '', propsSeed ? 'raw' : 'bip', propsType)); const [isMnemonicSaved, setIsMnemonicSaved] = useState(false); const [step, setStep] = useState(1); @@ -339,7 +339,7 @@ function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, typ help={t('Determines what cryptography will be used to create this account. Note that to validate on Polkadot, the session account must use "ed25519".')} label={t('keypair crypto type')} onChange={_onChangePairType} - options={uiSettings.availableCryptos} + options={isEthereum ? uiSettings.availableCryptosEth : uiSettings.availableCryptos} tabIndex={-1} /> diff --git a/packages/page-addresses/src/modals/Create.tsx b/packages/page-addresses/src/modals/Create.tsx index a602d6592999..6bb9117017b9 100644 --- a/packages/page-addresses/src/modals/Create.tsx +++ b/packages/page-addresses/src/modals/Create.tsx @@ -27,7 +27,7 @@ interface NameState { function Create ({ onClose, onStatusChange }: Props): React.ReactElement { const { t } = useTranslation(); - const { api } = useApi(); + const { api, isEthereum } = useApi(); const [{ isNameValid, name }, setName] = useState({ isNameValid: false, name: '' }); const [{ address, addressInput, isAddressExisting, isAddressValid }, setAddress] = useState({ address: '', addressInput: '', isAddressExisting: false, isAddressValid: false, isPublicKey: false }); const info = useCall(!!address && isAddressValid && api.derive.accounts.info, [address]); @@ -45,7 +45,7 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement address = keyring.encodeAddress(publicKey); isAddressValid = keyring.isAvailable(address); - isPublicKey = publicKey.length === 32; + isPublicKey = isEthereum? publicKey.length === 20:publicKey.length === 32; if (!isAddressValid) { const old = keyring.getAddress(address); diff --git a/packages/page-settings/src/util.tsx b/packages/page-settings/src/util.tsx index 0e522b79019c..455d9b6b9aa9 100644 --- a/packages/page-settings/src/util.tsx +++ b/packages/page-settings/src/util.tsx @@ -3,6 +3,7 @@ import { Option } from '@polkadot/apps-config/settings/types'; import { SettingsStruct } from '@polkadot/ui-settings/types'; +import { useApi } from '@polkadot/react-hooks'; import React from 'react'; import { ChainImg, Dropdown, IdentityIcon } from '@polkadot/react-components'; @@ -40,6 +41,7 @@ export function createOption ({ info, isHeader, text, value }: Option, overrides } export function createIdenticon ({ info, text, value }: Option, overrides: string[] = [], override = 'empty'): Option { + const { isEthereum } = useApi(); const theme = info && overrides.includes(info) ? override as 'empty' : info as 'substrate'; @@ -60,7 +62,7 @@ export function createIdenticon ({ info, text, value }: Option, overrides: strin : ( diff --git a/packages/page-signing/src/Verify.tsx b/packages/page-signing/src/Verify.tsx index cafbbcb632a1..93caaa8e0b5c 100644 --- a/packages/page-signing/src/Verify.tsx +++ b/packages/page-signing/src/Verify.tsx @@ -66,6 +66,7 @@ function Verify ({ className = '' }: Props): React.ReactElement { const _onChangeAddress = useCallback( (accountId: string | null): void => { + console.log('TODO:H160') let publicKey: Uint8Array | null = null; try { diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 468bd65b9109..d0eff1770d94 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -162,12 +162,15 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise Date: Tue, 3 Nov 2020 15:21:26 +0100 Subject: [PATCH 10/33] corrections --- packages/page-addresses/src/modals/Create.tsx | 4 ++- .../src/IdentityIcon/index.tsx | 31 +++++++++++-------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/packages/page-addresses/src/modals/Create.tsx b/packages/page-addresses/src/modals/Create.tsx index 6bb9117017b9..f91a23f3eb05 100644 --- a/packages/page-addresses/src/modals/Create.tsx +++ b/packages/page-addresses/src/modals/Create.tsx @@ -45,7 +45,9 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement address = keyring.encodeAddress(publicKey); isAddressValid = keyring.isAvailable(address); - isPublicKey = isEthereum? publicKey.length === 20:publicKey.length === 32; + console.log('TODO:H160') + console.log(publicKey.length) + isPublicKey = publicKey.length === 32; if (!isAddressValid) { const old = keyring.getAddress(address); diff --git a/packages/react-components/src/IdentityIcon/index.tsx b/packages/react-components/src/IdentityIcon/index.tsx index aa7e8cf87ffb..9021549a3800 100644 --- a/packages/react-components/src/IdentityIcon/index.tsx +++ b/packages/react-components/src/IdentityIcon/index.tsx @@ -14,6 +14,8 @@ import StatusContext from '../Status/Context'; import { useTranslation } from '../translate'; import RoboHash from './RoboHash'; +import makeBlockie from 'ethereum-blockies-base64'; + interface Props { className?: string; prefix?: IdentityProps['prefix']; @@ -27,7 +29,7 @@ export function getIdentityTheme (systemName: string): 'substrate' { } function IdentityIcon ({ className = '', prefix, size = 24, theme, value }: Props): React.ReactElement { - const { systemName } = useApi(); + const { systemName, isEthereum } = useApi(); const { t } = useTranslation(); const { queueAction } = useContext(StatusContext); const thisTheme = theme || getIdentityTheme(systemName); @@ -44,18 +46,21 @@ function IdentityIcon ({ className = '', prefix, size = 24, theme, value }: Prop }), [queueAction, t] ); - - return ( - - ); + if (isEthereum){ + return + } else { + return ( + + ); + } } export default React.memo(styled(IdentityIcon)` From 4d3863eebc69dc0dd8c4fe106d2ec03cc15d343f Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 3 Nov 2020 16:30:49 +0100 Subject: [PATCH 11/33] add standalone url and ethereum identicons --- packages/react-api/src/Api.tsx | 2 +- packages/react-components/src/IdentityIcon/index.tsx | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index d0eff1770d94..082dd2c53713 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -162,7 +162,7 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise - } else { return ( ); - } } export default React.memo(styled(IdentityIcon)` From 94dafe6eecc3f6fc627f270761991c7800b23aba Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 3 Nov 2020 18:51:54 +0100 Subject: [PATCH 12/33] add moonbeam config --- packages/apps-config/src/api/spec/index.ts | 4 ++++ packages/apps-config/src/api/spec/moonbeam.ts | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 packages/apps-config/src/api/spec/moonbeam.ts diff --git a/packages/apps-config/src/api/spec/index.ts b/packages/apps-config/src/api/spec/index.ts index fd5431478c5f..e7fd20860e7a 100644 --- a/packages/apps-config/src/api/spec/index.ts +++ b/packages/apps-config/src/api/spec/index.ts @@ -15,6 +15,7 @@ import equilibrium from './equilibrium'; import hanonycash from './hanonycash'; import kilt from './kilt'; import kulupu from './kulupu'; +import moonbeam from './moonbeam'; import nodeTemplate from './node-template'; import nodle from './nodle'; import plasm from './plasm'; @@ -42,6 +43,9 @@ export default { hanonycash, kulupu, 'mashnet-node': kilt, + 'node-moonbeam': moonbeam, + 'moonbase-alphanet': moonbeam, + 'moonbeam-standalone': moonbeam, 'node-template': nodeTemplate, 'nodle-chain': nodle, plasm, diff --git a/packages/apps-config/src/api/spec/moonbeam.ts b/packages/apps-config/src/api/spec/moonbeam.ts new file mode 100644 index 000000000000..c2c5d7a68f40 --- /dev/null +++ b/packages/apps-config/src/api/spec/moonbeam.ts @@ -0,0 +1,17 @@ +// Copyright 2017-2020 @polkadot/apps-config authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +// structs need to be in order +/* eslint-disable sort-keys */ + +export default { + Account: { + nonce: 'U256', + balance: 'U256', + }, + AccountId: 'EthereumAccountId', + Address: 'AccountId', + Balance: 'u128', + LookupSource: 'AccountId' +}; \ No newline at end of file From 5bda4dfe65bb3114d22702c54f5ee4d4374228c6 Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 3 Nov 2020 18:56:34 +0100 Subject: [PATCH 13/33] added changes from the old pr --- packages/react-components/src/IdentityIcon/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-components/src/IdentityIcon/index.tsx b/packages/react-components/src/IdentityIcon/index.tsx index 67f789d62646..3fa2e4812caf 100644 --- a/packages/react-components/src/IdentityIcon/index.tsx +++ b/packages/react-components/src/IdentityIcon/index.tsx @@ -52,7 +52,7 @@ function IdentityIcon ({ className = '', prefix, size = 24, theme, value }: Prop prefix={prefix} size={size} theme={isEthereum? 'ethereum' : thisTheme as 'substrate'} - value={value.length==42? value+"000000":value} + value={value} /> ); } From 379923a587f80c04a46b3b0d650010e7b008f110 Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 4 Nov 2020 10:35:15 +0100 Subject: [PATCH 14/33] add new config --- packages/apps-config/src/api/spec/moonbeam.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/apps-config/src/api/spec/moonbeam.ts b/packages/apps-config/src/api/spec/moonbeam.ts index c2c5d7a68f40..85afae0c3d08 100644 --- a/packages/apps-config/src/api/spec/moonbeam.ts +++ b/packages/apps-config/src/api/spec/moonbeam.ts @@ -13,5 +13,6 @@ export default { AccountId: 'EthereumAccountId', Address: 'AccountId', Balance: 'u128', + RefCount: "u8", LookupSource: 'AccountId' }; \ No newline at end of file From ab9a0e102f43a03127db82091c39e5612aec6f7e Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 4 Nov 2020 11:38:14 +0100 Subject: [PATCH 15/33] added dummy rpc method declarations for eth methods --- packages/react-api/src/Api.tsx | 8 ++-- packages/react-api/src/rpcMethods.ts | 59 ++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 packages/react-api/src/rpcMethods.ts diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 082dd2c53713..4943ecb65f39 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -4,6 +4,8 @@ import { InjectedExtension } from '@polkadot/extension-inject/types'; import { KeyringStore } from '@polkadot/ui-keyring/types'; import { ChainProperties, ChainType } from '@polkadot/types/interfaces'; +import {DefinitionRpc} from '@polkadot/types/types' +import getRPCMethods from './rpcMethods' import { ApiProps, ApiState } from './types'; import React, { useContext, useEffect, useMemo, useState } from 'react'; @@ -121,7 +123,6 @@ async function retrieve (api: ApiPromise, injectedPromise: Promise, store: KeyringStore | undefined, types: Record>): Promise { registry.register(types); - const { injectedAccounts, properties, systemChain, systemChainType, systemName, systemVersion } = await retrieve(api, injectedPromise); const ss58Format = uiSettings.prefix === -1 ? properties.ss58Format.unwrapOr(DEFAULT_SS58).toNumber() @@ -162,7 +163,7 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise | null const provider = new WsProvider(url); const signer = new ApiSigner(queuePayload, queueSetTxStatus); const types = getDevTypes(); + const rpc:Record> = getRPCMethods(); - api = new ApiPromise({ provider, registry, signer, types, typesBundle, typesChain, typesSpec }); + api = new ApiPromise({ provider, registry, signer, types, typesBundle, typesChain, typesSpec, rpc }); api.on('connected', () => setIsApiConnected(true)); api.on('disconnected', () => setIsApiConnected(false)); diff --git a/packages/react-api/src/rpcMethods.ts b/packages/react-api/src/rpcMethods.ts new file mode 100644 index 000000000000..ab27635534b8 --- /dev/null +++ b/packages/react-api/src/rpcMethods.ts @@ -0,0 +1,59 @@ + +import {DefinitionRpc} from '@polkadot/types/types' +export default function getRPCMethods ():Record> { + let dummyDescription={ + description: 'Just a test method', + params: [ + { + name: 'index', + type: 'u64' + }, + { + name: 'at', + type: 'Hash', + isOptional: true + } + ], + type: 'Balance' + } + return { + eth: { + accounts: dummyDescription, + blockNumber: dummyDescription, + call: dummyDescription, + chainId: dummyDescription, + coinbase: dummyDescription, + estimateGas: dummyDescription, + gasPrice: dummyDescription, + getBalance: dummyDescription, + getBlockByHash: dummyDescription, + getBlockByNumber: dummyDescription, + getBlockTransactionCountByHash: dummyDescription, + getBlockTransactionCountByNumber: dummyDescription, + getCode: dummyDescription, + getLogs: dummyDescription, + getStorageAt: dummyDescription, + getTransactionByBlockHashAndIndex: dummyDescription, + getTransactionByBlockNumberAndIndex: dummyDescription, + getTransactionByHash: dummyDescription, + getTransactionCount: dummyDescription, + getTransactionReceipt: dummyDescription, + getUncleByBlockHashAndIndex: dummyDescription, + getUncleByBlockNumberAndIndex: dummyDescription, + getUncleCountByBlockHash: dummyDescription, + getUncleCountByBlockNumber: dummyDescription, + getWork: dummyDescription, + hashrate: dummyDescription, + mining: dummyDescription, + protocolVersion: dummyDescription, + sendRawTransaction: dummyDescription, + submitHashrate: dummyDescription, + submitWork: dummyDescription, + subscribe: dummyDescription, + syncing: dummyDescription, + unsubscribe: dummyDescription, + net_listening: dummyDescription, + net_peerCount: dummyDescription, + net_version: dummyDescription + }}} + \ No newline at end of file From 05f0b5a53eea0a5075ea075ed2c354d5f3a9b520 Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 4 Nov 2020 12:56:28 +0100 Subject: [PATCH 16/33] wip fix address add modal --- packages/page-addresses/src/modals/Create.tsx | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/page-addresses/src/modals/Create.tsx b/packages/page-addresses/src/modals/Create.tsx index f91a23f3eb05..e94fb2e463ac 100644 --- a/packages/page-addresses/src/modals/Create.tsx +++ b/packages/page-addresses/src/modals/Create.tsx @@ -9,6 +9,8 @@ import React, { useCallback, useState } from 'react'; import { AddressRow, Button, Input, InputAddress, Modal } from '@polkadot/react-components'; import { useApi, useCall } from '@polkadot/react-hooks'; import keyring from '@polkadot/ui-keyring'; +import { hexToU8a } from '@polkadot/util'; +import { ethereumEncode } from '@polkadot/util-crypto'; import { useTranslation } from '../translate'; @@ -41,13 +43,19 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement let isPublicKey = false; try { - const publicKey = keyring.decodeAddress(addressInput); - - address = keyring.encodeAddress(publicKey); - isAddressValid = keyring.isAvailable(address); - console.log('TODO:H160') - console.log(publicKey.length) - isPublicKey = publicKey.length === 32; + if (isEthereum) { + const rawAddress = hexToU8a(addressInput); + + address = ethereumEncode(rawAddress); + console.log("rawaddy",rawAddress,rawAddress.length) + isPublicKey = rawAddress.length === 20; + console.log("isPublicKey",isPublicKey) + } else { + const publicKey = keyring.decodeAddress(addressInput); + + address = keyring.encodeAddress(publicKey); + isPublicKey = publicKey.length === 32; + } if (!isAddressValid) { const old = keyring.getAddress(address); @@ -64,10 +72,11 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement } catch (error) { isAddressValid = false; } + console.log("isAddressValid",isAddressValid) setAddress({ address: isAddressValid ? address : '', addressInput, isAddressExisting, isAddressValid, isPublicKey }); }, - [name] + [isEthereum, name] ); const _onChangeName = useCallback( From c60a567b1a1a9cbd7b95909b451fa251dbd220cd Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 4 Nov 2020 14:41:12 +0100 Subject: [PATCH 17/33] wip repair app with new keyring --- packages/react-api/src/Api.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 4943ecb65f39..a7440a5a5d26 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -130,14 +130,19 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise Date: Wed, 4 Nov 2020 15:07:09 +0100 Subject: [PATCH 18/33] use isDevelopement false for ethereum --- packages/react-api/src/Api.tsx | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index a7440a5a5d26..207fe12259d3 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -4,8 +4,8 @@ import { InjectedExtension } from '@polkadot/extension-inject/types'; import { KeyringStore } from '@polkadot/ui-keyring/types'; import { ChainProperties, ChainType } from '@polkadot/types/interfaces'; -import {DefinitionRpc} from '@polkadot/types/types' -import getRPCMethods from './rpcMethods' +import { DefinitionRpc } from '@polkadot/types/types'; +import getRPCMethods from './rpcMethods'; import { ApiProps, ApiState } from './types'; import React, { useContext, useEffect, useMemo, useState } from 'react'; @@ -132,17 +132,13 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise Date: Wed, 4 Nov 2020 15:43:18 +0100 Subject: [PATCH 19/33] lint --- packages/apps-config/src/api/spec/index.ts | 2 +- packages/apps-config/src/api/spec/moonbeam.ts | 11 +- packages/page-addresses/src/modals/Create.tsx | 7 +- packages/page-settings/src/util.tsx | 4 +- packages/page-signing/src/Verify.tsx | 2 +- packages/react-api/src/Api.tsx | 4 +- packages/react-api/src/rpcMethods.ts | 117 +++++++++--------- .../src/IdentityIcon/index.tsx | 25 ++-- 8 files changed, 87 insertions(+), 85 deletions(-) diff --git a/packages/apps-config/src/api/spec/index.ts b/packages/apps-config/src/api/spec/index.ts index e7fd20860e7a..1ad35a7b1a25 100644 --- a/packages/apps-config/src/api/spec/index.ts +++ b/packages/apps-config/src/api/spec/index.ts @@ -43,9 +43,9 @@ export default { hanonycash, kulupu, 'mashnet-node': kilt, - 'node-moonbeam': moonbeam, 'moonbase-alphanet': moonbeam, 'moonbeam-standalone': moonbeam, + 'node-moonbeam': moonbeam, 'node-template': nodeTemplate, 'nodle-chain': nodle, plasm, diff --git a/packages/apps-config/src/api/spec/moonbeam.ts b/packages/apps-config/src/api/spec/moonbeam.ts index 85afae0c3d08..098497c94e93 100644 --- a/packages/apps-config/src/api/spec/moonbeam.ts +++ b/packages/apps-config/src/api/spec/moonbeam.ts @@ -1,6 +1,5 @@ // Copyright 2017-2020 @polkadot/apps-config authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. +// SPDX-License-Identifier: Apache-2.0 // structs need to be in order /* eslint-disable sort-keys */ @@ -8,11 +7,11 @@ export default { Account: { nonce: 'U256', - balance: 'U256', + balance: 'U256' }, AccountId: 'EthereumAccountId', Address: 'AccountId', Balance: 'u128', - RefCount: "u8", - LookupSource: 'AccountId' -}; \ No newline at end of file + LookupSource: 'AccountId', + RefCount: 'u8' +}; diff --git a/packages/page-addresses/src/modals/Create.tsx b/packages/page-addresses/src/modals/Create.tsx index e94fb2e463ac..ac20020e329e 100644 --- a/packages/page-addresses/src/modals/Create.tsx +++ b/packages/page-addresses/src/modals/Create.tsx @@ -47,9 +47,9 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement const rawAddress = hexToU8a(addressInput); address = ethereumEncode(rawAddress); - console.log("rawaddy",rawAddress,rawAddress.length) + console.log('rawaddy', rawAddress, rawAddress.length); isPublicKey = rawAddress.length === 20; - console.log("isPublicKey",isPublicKey) + console.log('isPublicKey', isPublicKey); } else { const publicKey = keyring.decodeAddress(addressInput); @@ -72,7 +72,8 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement } catch (error) { isAddressValid = false; } - console.log("isAddressValid",isAddressValid) + + console.log('isAddressValid', isAddressValid); setAddress({ address: isAddressValid ? address : '', addressInput, isAddressExisting, isAddressValid, isPublicKey }); }, diff --git a/packages/page-settings/src/util.tsx b/packages/page-settings/src/util.tsx index 455d9b6b9aa9..0e522b79019c 100644 --- a/packages/page-settings/src/util.tsx +++ b/packages/page-settings/src/util.tsx @@ -3,7 +3,6 @@ import { Option } from '@polkadot/apps-config/settings/types'; import { SettingsStruct } from '@polkadot/ui-settings/types'; -import { useApi } from '@polkadot/react-hooks'; import React from 'react'; import { ChainImg, Dropdown, IdentityIcon } from '@polkadot/react-components'; @@ -41,7 +40,6 @@ export function createOption ({ info, isHeader, text, value }: Option, overrides } export function createIdenticon ({ info, text, value }: Option, overrides: string[] = [], override = 'empty'): Option { - const { isEthereum } = useApi(); const theme = info && overrides.includes(info) ? override as 'empty' : info as 'substrate'; @@ -62,7 +60,7 @@ export function createIdenticon ({ info, text, value }: Option, overrides: strin : ( diff --git a/packages/page-signing/src/Verify.tsx b/packages/page-signing/src/Verify.tsx index 93caaa8e0b5c..a6eb5dacdc01 100644 --- a/packages/page-signing/src/Verify.tsx +++ b/packages/page-signing/src/Verify.tsx @@ -66,7 +66,7 @@ function Verify ({ className = '' }: Props): React.ReactElement { const _onChangeAddress = useCallback( (accountId: string | null): void => { - console.log('TODO:H160') + console.log('TODO:H160'); let publicKey: Uint8Array | null = null; try { diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 207fe12259d3..4b15bb979aae 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -169,7 +169,7 @@ async function loadOnReady (api: ApiPromise, injectedPromise: Promise | null const types = getDevTypes(); const rpc:Record> = getRPCMethods(); - api = new ApiPromise({ provider, registry, signer, types, typesBundle, typesChain, typesSpec, rpc }); + api = new ApiPromise({ provider, registry, rpc, signer, types, typesBundle, typesChain, typesSpec }); api.on('connected', () => setIsApiConnected(true)); api.on('disconnected', () => setIsApiConnected(false)); diff --git a/packages/react-api/src/rpcMethods.ts b/packages/react-api/src/rpcMethods.ts index ab27635534b8..925a138a1656 100644 --- a/packages/react-api/src/rpcMethods.ts +++ b/packages/react-api/src/rpcMethods.ts @@ -1,59 +1,62 @@ +// Copyright 2017-2020 @polkadot/react-api authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import { DefinitionRpc } from '@polkadot/types/types'; -import {DefinitionRpc} from '@polkadot/types/types' export default function getRPCMethods ():Record> { - let dummyDescription={ - description: 'Just a test method', - params: [ - { - name: 'index', - type: 'u64' - }, - { - name: 'at', - type: 'Hash', - isOptional: true - } - ], - type: 'Balance' - } - return { - eth: { - accounts: dummyDescription, - blockNumber: dummyDescription, - call: dummyDescription, - chainId: dummyDescription, - coinbase: dummyDescription, - estimateGas: dummyDescription, - gasPrice: dummyDescription, - getBalance: dummyDescription, - getBlockByHash: dummyDescription, - getBlockByNumber: dummyDescription, - getBlockTransactionCountByHash: dummyDescription, - getBlockTransactionCountByNumber: dummyDescription, - getCode: dummyDescription, - getLogs: dummyDescription, - getStorageAt: dummyDescription, - getTransactionByBlockHashAndIndex: dummyDescription, - getTransactionByBlockNumberAndIndex: dummyDescription, - getTransactionByHash: dummyDescription, - getTransactionCount: dummyDescription, - getTransactionReceipt: dummyDescription, - getUncleByBlockHashAndIndex: dummyDescription, - getUncleByBlockNumberAndIndex: dummyDescription, - getUncleCountByBlockHash: dummyDescription, - getUncleCountByBlockNumber: dummyDescription, - getWork: dummyDescription, - hashrate: dummyDescription, - mining: dummyDescription, - protocolVersion: dummyDescription, - sendRawTransaction: dummyDescription, - submitHashrate: dummyDescription, - submitWork: dummyDescription, - subscribe: dummyDescription, - syncing: dummyDescription, - unsubscribe: dummyDescription, - net_listening: dummyDescription, - net_peerCount: dummyDescription, - net_version: dummyDescription - }}} - \ No newline at end of file + const dummyDescription = { + description: 'Just a test method', + params: [ + { + name: 'index', + type: 'u64' + }, + { + isOptional: true, + name: 'at', + type: 'Hash' + } + ], + type: 'Balance' + }; + + return { eth: { + accounts: dummyDescription, + blockNumber: dummyDescription, + call: dummyDescription, + chainId: dummyDescription, + coinbase: dummyDescription, + estimateGas: dummyDescription, + gasPrice: dummyDescription, + getBalance: dummyDescription, + getBlockByHash: dummyDescription, + getBlockByNumber: dummyDescription, + getBlockTransactionCountByHash: dummyDescription, + getBlockTransactionCountByNumber: dummyDescription, + getCode: dummyDescription, + getLogs: dummyDescription, + getStorageAt: dummyDescription, + getTransactionByBlockHashAndIndex: dummyDescription, + getTransactionByBlockNumberAndIndex: dummyDescription, + getTransactionByHash: dummyDescription, + getTransactionCount: dummyDescription, + getTransactionReceipt: dummyDescription, + getUncleByBlockHashAndIndex: dummyDescription, + getUncleByBlockNumberAndIndex: dummyDescription, + getUncleCountByBlockHash: dummyDescription, + getUncleCountByBlockNumber: dummyDescription, + getWork: dummyDescription, + hashrate: dummyDescription, + mining: dummyDescription, + net_listening: dummyDescription, + net_peerCount: dummyDescription, + net_version: dummyDescription, + protocolVersion: dummyDescription, + sendRawTransaction: dummyDescription, + submitHashrate: dummyDescription, + submitWork: dummyDescription, + subscribe: dummyDescription, + syncing: dummyDescription, + unsubscribe: dummyDescription + } }; +} diff --git a/packages/react-components/src/IdentityIcon/index.tsx b/packages/react-components/src/IdentityIcon/index.tsx index 3fa2e4812caf..76ecc53323c0 100644 --- a/packages/react-components/src/IdentityIcon/index.tsx +++ b/packages/react-components/src/IdentityIcon/index.tsx @@ -27,7 +27,7 @@ export function getIdentityTheme (systemName: string): 'substrate' { } function IdentityIcon ({ className = '', prefix, size = 24, theme, value }: Props): React.ReactElement { - const { systemName, isEthereum } = useApi(); + const { isEthereum, systemName } = useApi(); const { t } = useTranslation(); const { queueAction } = useContext(StatusContext); const thisTheme = theme || getIdentityTheme(systemName); @@ -44,17 +44,18 @@ function IdentityIcon ({ className = '', prefix, size = 24, theme, value }: Prop }), [queueAction, t] ); - return ( - - ); + + return ( + + ); } export default React.memo(styled(IdentityIcon)` From 4eaf8e75f4ecd2e2251dc186c549326f35169bfa Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 4 Nov 2020 16:55:46 +0100 Subject: [PATCH 20/33] more formatng --- packages/page-addresses/src/modals/Create.tsx | 4 - packages/react-api/src/rpcMethods.ts | 82 ++++++++++--------- 2 files changed, 43 insertions(+), 43 deletions(-) diff --git a/packages/page-addresses/src/modals/Create.tsx b/packages/page-addresses/src/modals/Create.tsx index ac20020e329e..f145b16f28cd 100644 --- a/packages/page-addresses/src/modals/Create.tsx +++ b/packages/page-addresses/src/modals/Create.tsx @@ -47,9 +47,7 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement const rawAddress = hexToU8a(addressInput); address = ethereumEncode(rawAddress); - console.log('rawaddy', rawAddress, rawAddress.length); isPublicKey = rawAddress.length === 20; - console.log('isPublicKey', isPublicKey); } else { const publicKey = keyring.decodeAddress(addressInput); @@ -73,8 +71,6 @@ function Create ({ onClose, onStatusChange }: Props): React.ReactElement isAddressValid = false; } - console.log('isAddressValid', isAddressValid); - setAddress({ address: isAddressValid ? address : '', addressInput, isAddressExisting, isAddressValid, isPublicKey }); }, [isEthereum, name] diff --git a/packages/react-api/src/rpcMethods.ts b/packages/react-api/src/rpcMethods.ts index 925a138a1656..e1ec6674f55d 100644 --- a/packages/react-api/src/rpcMethods.ts +++ b/packages/react-api/src/rpcMethods.ts @@ -20,43 +20,47 @@ export default function getRPCMethods ():Record Date: Wed, 4 Nov 2020 19:10:05 +0100 Subject: [PATCH 21/33] eth addresses by default for account creation --- packages/page-accounts/src/modals/Create.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/page-accounts/src/modals/Create.tsx b/packages/page-accounts/src/modals/Create.tsx index 94dc52a6044d..515b1ce11350 100644 --- a/packages/page-accounts/src/modals/Create.tsx +++ b/packages/page-accounts/src/modals/Create.tsx @@ -183,7 +183,7 @@ function createAccount (suri: string, pairType: KeypairType, { genesisHash, name function Create ({ className = '', onClose, onStatusChange, seed: propsSeed, type: propsType }: Props): React.ReactElement { const { t } = useTranslation(); const { api, isDevelopment, isEthereum } = useApi(); - const [{ address, derivePath, deriveValidation, isSeedValid, pairType, seed, seedType }, setAddress] = useState(generateSeed(propsSeed, '', propsSeed ? 'raw' : 'bip', propsType)); + const [{ address, derivePath, deriveValidation, isSeedValid, pairType, seed, seedType }, setAddress] = useState(generateSeed(propsSeed, '', propsSeed ? 'raw' : 'bip', isEthereum ? 'ethereum' : propsType)); const [isMnemonicSaved, setIsMnemonicSaved] = useState(false); const [step, setStep] = useState(1); const [isBusy, setIsBusy] = useState(false); From ee630e6de67860168b6e702c0bde35fec26c2a50 Mon Sep 17 00:00:00 2001 From: joelamouche Date: Fri, 6 Nov 2020 19:07:01 +0100 Subject: [PATCH 22/33] added many more types to support moonbeam --- packages/apps-config/src/api/spec/moonbeam.ts | 78 ++++++++++++++++--- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/packages/apps-config/src/api/spec/moonbeam.ts b/packages/apps-config/src/api/spec/moonbeam.ts index 098497c94e93..7ff2b355fe9a 100644 --- a/packages/apps-config/src/api/spec/moonbeam.ts +++ b/packages/apps-config/src/api/spec/moonbeam.ts @@ -1,17 +1,77 @@ // Copyright 2017-2020 @polkadot/apps-config authors & contributors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier": Apache-2.0 // structs need to be in order /* eslint-disable sort-keys */ export default { - Account: { - nonce: 'U256', - balance: 'U256' + "AccountId": "EthereumAccountId", + "Address": "AccountId", + "Balance": "u128", + "RefCount": "u8", + "LookupSource": "AccountId", + "Account": { + "nonce": "U256", + "balance": "u128" }, - AccountId: 'EthereumAccountId', - Address: 'AccountId', - Balance: 'u128', - LookupSource: 'AccountId', - RefCount: 'u8' + "TransactionCondition":{ + "_enum": { + "block": "u64", + "time": "u64" + } + }, + "Transaction": { + "action": "String", + "block_hash": "Option", + "block_number": "Option", + "chain_id": "Option", + "condition": "Option", + "creates": "Option", + "from": "H160", + "gas": "U256", + "gas_price": "U256", + "gas_limit": "u64", + "hash": "H256", + "input": "Bytes", + "nonce": "U256", + "public_key": "Option", + "r": "U256", + "raw": "Bytes", + "s": "U256", + "signature": "Signature", + "standard_v": "U256", + "to": "Option", + "transaction_index": "Option", + "v": "U256", + "value": "U256", + }, + "Signature": { + "v": "u64", + "r": "H256", + "s": "H256" + }, + "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", + } }; From 61552bfb5efe334ead3f32e03fbd3f649d4baf4c Mon Sep 17 00:00:00 2001 From: joelamouche Date: Mon, 9 Nov 2020 10:54:34 +0100 Subject: [PATCH 23/33] added color --- packages/apps-config/src/api/spec/moonbeam.ts | 2 +- packages/apps-config/src/ui/colors.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/apps-config/src/api/spec/moonbeam.ts b/packages/apps-config/src/api/spec/moonbeam.ts index 7ff2b355fe9a..4ca8caa509bd 100644 --- a/packages/apps-config/src/api/spec/moonbeam.ts +++ b/packages/apps-config/src/api/spec/moonbeam.ts @@ -1,5 +1,5 @@ // Copyright 2017-2020 @polkadot/apps-config authors & contributors -// SPDX-License-Identifier": Apache-2.0 +// SPDX-License-Identifier: Apache-2.0 // structs need to be in order /* eslint-disable sort-keys */ diff --git a/packages/apps-config/src/ui/colors.ts b/packages/apps-config/src/ui/colors.ts index 055ecf05d87d..21f56211513c 100644 --- a/packages/apps-config/src/ui/colors.ts +++ b/packages/apps-config/src/ui/colors.ts @@ -29,6 +29,7 @@ const nodeCanvas = '#c77cff'; const nodeCentrifuge = '#fcc367'; const nodeEdgeware = '#0a95df'; const nodeEquilibrium = '#1792ff'; +const nodeMoonbeam = '#53cbc9'; const nodeNodle = '#1ab394'; const nodeKilt = '#eb5b2a'; const nodeStafi = '#00F3AB'; @@ -71,6 +72,7 @@ const nodeColors: Record = [ ['edgeware node', nodeEdgeware], ['Equilibrium node', nodeEquilibrium], ['kilt node', nodeKilt], + ['moonbase alpha', nodeMoonbeam], ['nodle chain node', nodeNodle], ['Stafi node', nodeStafi], ['subsocial node', nodeSubsocial] From 6fc041a4da70ba9640ce52c6ef7a612ddd08c516 Mon Sep 17 00:00:00 2001 From: joelamouche Date: Mon, 9 Nov 2020 14:49:47 +0100 Subject: [PATCH 24/33] add h160 to types and components --- packages/react-params/src/Param/Hash160.tsx | 29 +++++++++++++++++++ .../react-params/src/Param/findComponent.ts | 2 ++ packages/react-params/src/initValue.ts | 4 +++ 3 files changed, 35 insertions(+) create mode 100644 packages/react-params/src/Param/Hash160.tsx diff --git a/packages/react-params/src/Param/Hash160.tsx b/packages/react-params/src/Param/Hash160.tsx new file mode 100644 index 000000000000..4d48143ef7f0 --- /dev/null +++ b/packages/react-params/src/Param/Hash160.tsx @@ -0,0 +1,29 @@ +// Copyright 2017-2020 @polkadot/react-params authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import { Props } from '../types'; + +import React from 'react'; + +import BaseBytes from './BaseBytes'; + +function Hash160 ({ className = '', defaultValue, isDisabled, isError, label, name, onChange, onEnter, onEscape, type, withLabel }: Props): React.ReactElement { + return ( + + ); +} + +export default React.memo(Hash160); diff --git a/packages/react-params/src/Param/findComponent.ts b/packages/react-params/src/Param/findComponent.ts index e5a88e2091c8..c8b7b62c556c 100644 --- a/packages/react-params/src/Param/findComponent.ts +++ b/packages/react-params/src/Param/findComponent.ts @@ -18,6 +18,7 @@ import Code from './Code'; import DispatchError from './DispatchError'; import Enum from './Enum'; import Hash256 from './Hash256'; +import Hash160 from './Hash160'; import Hash512 from './Hash512'; import KeyValue from './KeyValue'; import KeyValueArray from './KeyValueArray'; @@ -54,6 +55,7 @@ const componentDef: TypeToComponent[] = [ { c: Raw, t: ['Raw', 'Keys'] }, { c: Enum, t: ['Enum'] }, { c: Hash256, t: ['BlockHash', 'CodeHash', 'Hash', 'H256', 'SeedOf'] }, + { c: Hash160, t: ['BlockHash', 'CodeHash', 'Hash', 'H160', 'SeedOf'] }, { c: Hash512, t: ['H512', 'Signature'] }, { c: KeyValue, t: ['KeyValue'] }, { c: KeyValueArray, t: ['Vec'] }, diff --git a/packages/react-params/src/initValue.ts b/packages/react-params/src/initValue.ts index 4cb6d042402c..d6e9493a1244 100644 --- a/packages/react-params/src/initValue.ts +++ b/packages/react-params/src/initValue.ts @@ -88,6 +88,9 @@ export default function getInitValue (def: TypeDef): unknown { case 'H512': return createType(registry, 'H512'); + case 'H160': + return createType(registry, 'H160'); + case 'Raw': case 'Keys': return ''; @@ -100,6 +103,7 @@ export default function getInitValue (def: TypeDef): unknown { case 'Digest': case 'Header': case 'KeyValue': + case 'LookupSource': case 'MisbehaviorReport': case 'Proposal': case 'Signature': From e6181054c5180cde4181b1a7a030716bb78dcb3c Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 10 Nov 2020 10:56:28 +0100 Subject: [PATCH 25/33] add rpc methods to app-config --- packages/apps-config/src/api/index.ts | 4 +++- packages/apps-config/src/api/rpc/index.ts | 10 ++++++++++ .../src/api/rpc/moonbeam.ts} | 2 +- packages/react-api/src/Api.tsx | 16 +++++++++++----- 4 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 packages/apps-config/src/api/rpc/index.ts rename packages/{react-api/src/rpcMethods.ts => apps-config/src/api/rpc/moonbeam.ts} (95%) diff --git a/packages/apps-config/src/api/index.ts b/packages/apps-config/src/api/index.ts index f878496a2982..7f45f3d81b20 100644 --- a/packages/apps-config/src/api/index.ts +++ b/packages/apps-config/src/api/index.ts @@ -4,6 +4,7 @@ import typesChain from './chain'; import typesSpec from './spec'; import typesBundle from './bundle'; +import typesRpc from './rpc'; export function getChainTypes (specName: string, chainName: string): Record> { return { @@ -15,5 +16,6 @@ export function getChainTypes (specName: string, chainName: string): Record> { +export default function ():Record> { const dummyDescription = { description: 'Just a test method', params: [ diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 4b15bb979aae..e7fac1d03c5e 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -4,15 +4,13 @@ import { InjectedExtension } from '@polkadot/extension-inject/types'; import { KeyringStore } from '@polkadot/ui-keyring/types'; import { ChainProperties, ChainType } from '@polkadot/types/interfaces'; -import { DefinitionRpc } from '@polkadot/types/types'; -import getRPCMethods from './rpcMethods'; import { ApiProps, ApiState } from './types'; import React, { useContext, useEffect, useMemo, useState } from 'react'; import store from 'store'; import ApiPromise from '@polkadot/api/promise'; import { setDeriveCache, deriveMapCache } from '@polkadot/api-derive/util'; -import { typesChain, typesSpec, typesBundle } from '@polkadot/apps-config/api'; +import { typesChain, typesSpec, typesBundle, typesRpc } from '@polkadot/apps-config/api'; import { POLKADOT_DENOM_BLOCK, POLKADOT_GENESIS } from '@polkadot/apps-config/api/constants'; import { web3Accounts, web3Enable } from '@polkadot/extension-dapp'; import { WsProvider } from '@polkadot/rpc-provider'; @@ -77,6 +75,15 @@ function getDevTypes (): Record> { return types; } +// function getRpcTypes (): Record> { +// const types = store.get('types', {}) as Record>; +// const names = Object.keys(types); + +// names.length && console.log('Injected types:', names.join(', ')); + +// return types; +// } + async function retrieve (api: ApiPromise, injectedPromise: Promise): Promise { const [bestHeader, chainProperties, systemChain, systemChainType, systemName, systemVersion, injectedAccounts] = await Promise.all([ api.rpc.chain.getHeader(), @@ -194,9 +201,8 @@ function Api ({ children, store, url }: Props): React.ReactElement | null const provider = new WsProvider(url); const signer = new ApiSigner(queuePayload, queueSetTxStatus); const types = getDevTypes(); - const rpc:Record> = getRPCMethods(); - api = new ApiPromise({ provider, registry, rpc, signer, types, typesBundle, typesChain, typesSpec }); + api = new ApiPromise({ provider, registry, rpc:typesRpc, signer, types, typesBundle, typesChain, typesSpec }); api.on('connected', () => setIsApiConnected(true)); api.on('disconnected', () => setIsApiConnected(false)); From da71df311796de0295d84bbdb697b587db49125f Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 10 Nov 2020 11:07:59 +0100 Subject: [PATCH 26/33] lint --- packages/apps-config/src/api/rpc/index.ts | 2 +- packages/apps-config/src/api/spec/moonbeam.ts | 124 +++++++++--------- packages/react-api/src/Api.tsx | 2 +- packages/react-params/src/initValue.ts | 2 +- 4 files changed, 65 insertions(+), 65 deletions(-) diff --git a/packages/apps-config/src/api/rpc/index.ts b/packages/apps-config/src/api/rpc/index.ts index bc64cf5506e5..e52f409c8461 100644 --- a/packages/apps-config/src/api/rpc/index.ts +++ b/packages/apps-config/src/api/rpc/index.ts @@ -6,5 +6,5 @@ import moonbeam from './moonbeam'; // mapping from specName in state.getRuntimeVersion export default { // Moonbeam rpc types (Frontier) - ...moonbeam(), + ...moonbeam() }; diff --git a/packages/apps-config/src/api/spec/moonbeam.ts b/packages/apps-config/src/api/spec/moonbeam.ts index 4ca8caa509bd..a9886a7b9b53 100644 --- a/packages/apps-config/src/api/spec/moonbeam.ts +++ b/packages/apps-config/src/api/spec/moonbeam.ts @@ -5,73 +5,73 @@ /* eslint-disable sort-keys */ export default { - "AccountId": "EthereumAccountId", - "Address": "AccountId", - "Balance": "u128", - "RefCount": "u8", - "LookupSource": "AccountId", - "Account": { - "nonce": "U256", - "balance": "u128" + AccountId: 'EthereumAccountId', + Address: 'AccountId', + Balance: 'u128', + RefCount: 'u8', + LookupSource: 'AccountId', + Account: { + nonce: 'U256', + balance: 'u128' }, - "TransactionCondition":{ - "_enum": { - "block": "u64", - "time": "u64" + TransactionCondition: { + _enum: { + block: 'u64', + time: 'u64' } }, - "Transaction": { - "action": "String", - "block_hash": "Option", - "block_number": "Option", - "chain_id": "Option", - "condition": "Option", - "creates": "Option", - "from": "H160", - "gas": "U256", - "gas_price": "U256", - "gas_limit": "u64", - "hash": "H256", - "input": "Bytes", - "nonce": "U256", - "public_key": "Option", - "r": "U256", - "raw": "Bytes", - "s": "U256", - "signature": "Signature", - "standard_v": "U256", - "to": "Option", - "transaction_index": "Option", - "v": "U256", - "value": "U256", + Transaction: { + action: 'String', + block_hash: 'Option', + block_number: 'Option', + chain_id: 'Option', + condition: 'Option', + creates: 'Option', + from: 'H160', + gas: 'U256', + gas_price: 'U256', + gas_limit: 'u64', + hash: 'H256', + input: 'Bytes', + nonce: 'U256', + public_key: 'Option', + r: 'U256', + raw: 'Bytes', + s: 'U256', + signature: 'Signature', + standard_v: 'U256', + to: 'Option', + transaction_index: 'Option', + v: 'U256', + value: 'U256' }, - "Signature": { - "v": "u64", - "r": "H256", - "s": "H256" + Signature: { + v: 'u64', + r: 'H256', + s: 'H256' }, - "TransactionStatus": { - "transaction_hash": "H256", - "transaction_index": "u32", - "from": "H160", - "to": "Option", - "contract_address": "Option", - "logs": "Vec", - "logs_bloom": "Bloom", + 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", + 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' } }; diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index e7fac1d03c5e..1a87983e5142 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -202,7 +202,7 @@ function Api ({ children, store, url }: Props): React.ReactElement | null const signer = new ApiSigner(queuePayload, queueSetTxStatus); const types = getDevTypes(); - api = new ApiPromise({ provider, registry, rpc:typesRpc, signer, types, typesBundle, typesChain, typesSpec }); + api = new ApiPromise({ provider, registry, rpc: typesRpc, signer, types, typesBundle, typesChain, typesSpec }); api.on('connected', () => setIsApiConnected(true)); api.on('disconnected', () => setIsApiConnected(false)); diff --git a/packages/react-params/src/initValue.ts b/packages/react-params/src/initValue.ts index d6e9493a1244..c3140e6f68e1 100644 --- a/packages/react-params/src/initValue.ts +++ b/packages/react-params/src/initValue.ts @@ -89,7 +89,7 @@ export default function getInitValue (def: TypeDef): unknown { return createType(registry, 'H512'); case 'H160': - return createType(registry, 'H160'); + return createType(registry, 'H160'); case 'Raw': case 'Keys': From 16e94a8b02c38e2f0b4ac6d08822a06abad273aa Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 10 Nov 2020 11:16:32 +0100 Subject: [PATCH 27/33] polish --- packages/apps-config/src/api/rpc/index.ts | 2 +- packages/apps-config/src/api/rpc/moonbeam.ts | 2 +- packages/page-signing/src/Verify.tsx | 1 - packages/react-api/src/Api.tsx | 9 --------- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/packages/apps-config/src/api/rpc/index.ts b/packages/apps-config/src/api/rpc/index.ts index e52f409c8461..697be74282eb 100644 --- a/packages/apps-config/src/api/rpc/index.ts +++ b/packages/apps-config/src/api/rpc/index.ts @@ -3,7 +3,7 @@ import moonbeam from './moonbeam'; -// mapping from specName in state.getRuntimeVersion +// Add your rpc method definitions here export default { // Moonbeam rpc types (Frontier) ...moonbeam() diff --git a/packages/apps-config/src/api/rpc/moonbeam.ts b/packages/apps-config/src/api/rpc/moonbeam.ts index 30559085b1ec..91b6e8a3a8bb 100644 --- a/packages/apps-config/src/api/rpc/moonbeam.ts +++ b/packages/apps-config/src/api/rpc/moonbeam.ts @@ -1,4 +1,4 @@ -// Copyright 2017-2020 @polkadot/react-api authors & contributors +// Copyright 2017-2020 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 import { DefinitionRpc } from '@polkadot/types/types'; diff --git a/packages/page-signing/src/Verify.tsx b/packages/page-signing/src/Verify.tsx index a6eb5dacdc01..cafbbcb632a1 100644 --- a/packages/page-signing/src/Verify.tsx +++ b/packages/page-signing/src/Verify.tsx @@ -66,7 +66,6 @@ function Verify ({ className = '' }: Props): React.ReactElement { const _onChangeAddress = useCallback( (accountId: string | null): void => { - console.log('TODO:H160'); let publicKey: Uint8Array | null = null; try { diff --git a/packages/react-api/src/Api.tsx b/packages/react-api/src/Api.tsx index 1a87983e5142..cea7c6263e6c 100644 --- a/packages/react-api/src/Api.tsx +++ b/packages/react-api/src/Api.tsx @@ -75,15 +75,6 @@ function getDevTypes (): Record> { return types; } -// function getRpcTypes (): Record> { -// const types = store.get('types', {}) as Record>; -// const names = Object.keys(types); - -// names.length && console.log('Injected types:', names.join(', ')); - -// return types; -// } - async function retrieve (api: ApiPromise, injectedPromise: Promise): Promise { const [bestHeader, chainProperties, systemChain, systemChainType, systemName, systemVersion, injectedAccounts] = await Promise.all([ api.rpc.chain.getHeader(), From 7e2a535e0febc89cb2d49826d523e6327286321b Mon Sep 17 00:00:00 2001 From: Antoine Estienne Date: Tue, 10 Nov 2020 11:17:40 +0100 Subject: [PATCH 28/33] Update packages/react-params/src/initValue.ts Co-authored-by: Jaco Greeff --- packages/react-params/src/initValue.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-params/src/initValue.ts b/packages/react-params/src/initValue.ts index c3140e6f68e1..f598e1e9bb8e 100644 --- a/packages/react-params/src/initValue.ts +++ b/packages/react-params/src/initValue.ts @@ -89,7 +89,7 @@ export default function getInitValue (def: TypeDef): unknown { return createType(registry, 'H512'); case 'H160': - return createType(registry, 'H160'); + return registry.createType('H160'); case 'Raw': case 'Keys': From 706f0312a6b47898359a49c9df786e4b3889173f Mon Sep 17 00:00:00 2001 From: Antoine Estienne Date: Tue, 10 Nov 2020 12:36:59 +0100 Subject: [PATCH 29/33] Apply suggestions from code review Co-authored-by: Jaco Greeff --- packages/apps-config/src/api/rpc/moonbeam.ts | 2 +- packages/page-accounts/src/Vanity/index.tsx | 2 +- packages/react-api/src/types.ts | 2 +- packages/react-params/src/Param/findComponent.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/apps-config/src/api/rpc/moonbeam.ts b/packages/apps-config/src/api/rpc/moonbeam.ts index 91b6e8a3a8bb..71b4682db7fb 100644 --- a/packages/apps-config/src/api/rpc/moonbeam.ts +++ b/packages/apps-config/src/api/rpc/moonbeam.ts @@ -3,7 +3,7 @@ import { DefinitionRpc } from '@polkadot/types/types'; -export default function ():Record> { +export default function (): Record> { const dummyDescription = { description: 'Just a test method', params: [ diff --git a/packages/page-accounts/src/Vanity/index.tsx b/packages/page-accounts/src/Vanity/index.tsx index 8d7419b9b92e..625068349e03 100644 --- a/packages/page-accounts/src/Vanity/index.tsx +++ b/packages/page-accounts/src/Vanity/index.tsx @@ -8,7 +8,7 @@ import { GeneratorMatches, GeneratorMatch, GeneratorResult } from '@polkadot/van import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import styled from 'styled-components'; import { Button, Dropdown, Input, Table } from '@polkadot/react-components'; -import { useIsMountedRef, useApi } from '@polkadot/react-hooks'; +import { useApi, useIsMountedRef } from '@polkadot/react-hooks'; import uiSettings from '@polkadot/ui-settings'; import generator from '@polkadot/vanitygen/generator'; import matchRegex from '@polkadot/vanitygen/regex'; diff --git a/packages/react-api/src/types.ts b/packages/react-api/src/types.ts index 9af373d3fe17..217a0410b815 100644 --- a/packages/react-api/src/types.ts +++ b/packages/react-api/src/types.ts @@ -20,7 +20,7 @@ export interface ApiState { hasInjectedAccounts: boolean; isApiReady: boolean; isDevelopment: boolean; - isEthereum:boolean; + isEthereum: boolean; isSubstrateV2: boolean; systemChain: string; systemName: string; diff --git a/packages/react-params/src/Param/findComponent.ts b/packages/react-params/src/Param/findComponent.ts index c8b7b62c556c..6b916320d71b 100644 --- a/packages/react-params/src/Param/findComponent.ts +++ b/packages/react-params/src/Param/findComponent.ts @@ -55,7 +55,7 @@ const componentDef: TypeToComponent[] = [ { c: Raw, t: ['Raw', 'Keys'] }, { c: Enum, t: ['Enum'] }, { c: Hash256, t: ['BlockHash', 'CodeHash', 'Hash', 'H256', 'SeedOf'] }, - { c: Hash160, t: ['BlockHash', 'CodeHash', 'Hash', 'H160', 'SeedOf'] }, + { c: Hash160, t: ['H160'] }, { c: Hash512, t: ['H512', 'Signature'] }, { c: KeyValue, t: ['KeyValue'] }, { c: KeyValueArray, t: ['Vec'] }, From 58ca9c88709b65f4c13bec777a07386ee01cd164 Mon Sep 17 00:00:00 2001 From: joelamouche Date: Tue, 10 Nov 2020 12:55:09 +0100 Subject: [PATCH 30/33] mobe to typesBundle --- packages/apps-config/src/api/bundle/spec/index.ts | 7 ++++++- packages/apps-config/src/api/{ => bundle}/spec/moonbeam.ts | 4 +++- packages/apps-config/src/api/spec/index.ts | 4 ---- 3 files changed, 9 insertions(+), 6 deletions(-) rename packages/apps-config/src/api/{ => bundle}/spec/moonbeam.ts (94%) diff --git a/packages/apps-config/src/api/bundle/spec/index.ts b/packages/apps-config/src/api/bundle/spec/index.ts index 852364ef17ab..7d54238046bf 100644 --- a/packages/apps-config/src/api/bundle/spec/index.ts +++ b/packages/apps-config/src/api/bundle/spec/index.ts @@ -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 }; diff --git a/packages/apps-config/src/api/spec/moonbeam.ts b/packages/apps-config/src/api/bundle/spec/moonbeam.ts similarity index 94% rename from packages/apps-config/src/api/spec/moonbeam.ts rename to packages/apps-config/src/api/bundle/spec/moonbeam.ts index a9886a7b9b53..391a919ca57d 100644 --- a/packages/apps-config/src/api/spec/moonbeam.ts +++ b/packages/apps-config/src/api/bundle/spec/moonbeam.ts @@ -1,6 +1,8 @@ // 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 */ @@ -74,4 +76,4 @@ export default { logs_bloom: 'H2048', status_code: 'Option' } -}; +} as OverrideBundleDefinition; diff --git a/packages/apps-config/src/api/spec/index.ts b/packages/apps-config/src/api/spec/index.ts index 5adddd90ecc0..97d692f62c44 100644 --- a/packages/apps-config/src/api/spec/index.ts +++ b/packages/apps-config/src/api/spec/index.ts @@ -16,7 +16,6 @@ import equilibrium from './equilibrium'; import hanonycash from './hanonycash'; import kilt from './kilt'; import kulupu from './kulupu'; -import moonbeam from './moonbeam'; import nodeTemplate from './node-template'; import nodle from './nodle'; import plasm from './plasm'; @@ -45,9 +44,6 @@ export default { hanonycash, kulupu, 'mashnet-node': kilt, - 'moonbase-alphanet': moonbeam, - 'moonbeam-standalone': moonbeam, - 'node-moonbeam': moonbeam, 'node-template': nodeTemplate, 'nodle-chain': nodle, plasm, From 712af035a63369780f28f1a459ee5096960fd3ba Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 11 Nov 2020 12:13:14 +0100 Subject: [PATCH 31/33] added right type for types declaration --- packages/apps-config/src/api/bundle/spec/moonbeam.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/apps-config/src/api/bundle/spec/moonbeam.ts b/packages/apps-config/src/api/bundle/spec/moonbeam.ts index 391a919ca57d..9a08e3f555fa 100644 --- a/packages/apps-config/src/api/bundle/spec/moonbeam.ts +++ b/packages/apps-config/src/api/bundle/spec/moonbeam.ts @@ -1,12 +1,14 @@ // Copyright 2017-2020 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { OverrideBundleDefinition } from '@polkadot/types/types'; +import { OverrideVersionedType } from '@polkadot/types/types'; // structs need to be in order /* eslint-disable sort-keys */ -export default { +export default [{ + minmax: [0, undefined], + types:{ AccountId: 'EthereumAccountId', Address: 'AccountId', Balance: 'u128', @@ -76,4 +78,4 @@ export default { logs_bloom: 'H2048', status_code: 'Option' } -} as OverrideBundleDefinition; +} }]as OverrideVersionedType[]; From 8d56f394e3f9765cc3c3eca922ec032c2ef444ed Mon Sep 17 00:00:00 2001 From: joelamouche Date: Wed, 11 Nov 2020 12:21:43 +0100 Subject: [PATCH 32/33] lint --- .../apps-config/src/api/bundle/spec/index.ts | 4 +- .../src/api/bundle/spec/moonbeam.ts | 143 +++++++++--------- packages/apps-config/src/api/rpc/moonbeam.ts | 140 ++++++++--------- 3 files changed, 143 insertions(+), 144 deletions(-) diff --git a/packages/apps-config/src/api/bundle/spec/index.ts b/packages/apps-config/src/api/bundle/spec/index.ts index 7d54238046bf..b1cf50da43b8 100644 --- a/packages/apps-config/src/api/bundle/spec/index.ts +++ b/packages/apps-config/src/api/bundle/spec/index.ts @@ -10,7 +10,7 @@ export default { laminar, mandala: acala, 'moonbase-alphanet': moonbeam, + moonbeam, 'moonbeam-standalone': moonbeam, - 'node-moonbeam': moonbeam, - moonbeam + 'node-moonbeam': moonbeam }; diff --git a/packages/apps-config/src/api/bundle/spec/moonbeam.ts b/packages/apps-config/src/api/bundle/spec/moonbeam.ts index 9a08e3f555fa..d908b4536269 100644 --- a/packages/apps-config/src/api/bundle/spec/moonbeam.ts +++ b/packages/apps-config/src/api/bundle/spec/moonbeam.ts @@ -6,76 +6,75 @@ import { OverrideVersionedType } from '@polkadot/types/types'; // structs need to be in order /* eslint-disable sort-keys */ -export default [{ - minmax: [0, undefined], - types:{ - AccountId: 'EthereumAccountId', - Address: 'AccountId', - Balance: 'u128', - RefCount: 'u8', - LookupSource: 'AccountId', - Account: { - nonce: 'U256', - balance: 'u128' - }, - TransactionCondition: { - _enum: { - block: 'u64', - time: 'u64' +export default [{ minmax: [0, undefined], + types: { + 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', + block_number: 'Option', + chain_id: 'Option', + condition: 'Option', + creates: 'Option', + from: 'H160', + gas: 'U256', + gas_price: 'U256', + gas_limit: 'u64', + hash: 'H256', + input: 'Bytes', + nonce: 'U256', + public_key: 'Option', + r: 'U256', + raw: 'Bytes', + s: 'U256', + signature: 'Signature', + standard_v: 'U256', + to: 'Option', + transaction_index: 'Option', + v: 'U256', + value: 'U256' + }, + Signature: { + v: 'u64', + r: 'H256', + s: 'H256' + }, + 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' } - }, - Transaction: { - action: 'String', - block_hash: 'Option', - block_number: 'Option', - chain_id: 'Option', - condition: 'Option', - creates: 'Option', - from: 'H160', - gas: 'U256', - gas_price: 'U256', - gas_limit: 'u64', - hash: 'H256', - input: 'Bytes', - nonce: 'U256', - public_key: 'Option', - r: 'U256', - raw: 'Bytes', - s: 'U256', - signature: 'Signature', - standard_v: 'U256', - to: 'Option', - transaction_index: 'Option', - v: 'U256', - value: 'U256' - }, - Signature: { - v: 'u64', - r: 'H256', - s: 'H256' - }, - 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' - } -} }]as OverrideVersionedType[]; + } }]as OverrideVersionedType[]; diff --git a/packages/apps-config/src/api/rpc/moonbeam.ts b/packages/apps-config/src/api/rpc/moonbeam.ts index a221829a8349..fef95aaab0ea 100644 --- a/packages/apps-config/src/api/rpc/moonbeam.ts +++ b/packages/apps-config/src/api/rpc/moonbeam.ts @@ -1,10 +1,10 @@ // 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> { - function generateDescription( +export default function (): Record> { + function generateDescription ( description: string, returnType: string, params: DefinitionRpcParam[] = [] @@ -16,134 +16,134 @@ export default function(): Record> { }; } - 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"), - blockNumber: generateDescription("Returns balance of the given account.", "U256"), - call: generateDescription("Call contract, returning the output data.", "Bytes", [reqParam, numberParam]), + 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" + '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", [ + 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", [ + 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" } + { isOptional: true, name: 'full', type: 'bool' } ]), - getBlockByNumber: generateDescription("Returns block with given number.", "RichBlock", [ + getBlockByNumber: generateDescription('Returns block with given number.', 'RichBlock', [ blockParam, - { isOptional: true, name: "full", type: "bool" } + { isOptional: true, name: 'full', type: 'bool' } ]), getBlockTransactionCountByHash: generateDescription( - "Returns the number of transactions in a block with given hash.", - "U256", + '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", + '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", [ + 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" } + getLogs: generateDescription('Returns logs matching given filter object.', 'Vec', [ + { name: 'filter', type: 'Filter' } ]), - getStorageAt: generateDescription("Returns content of the storage at given address.", "H256", [ + 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", + 'Returns transaction at given block hash and index.', + 'Transaction', [hashParam, indexParam] ), getTransactionByBlockNumberAndIndex: generateDescription( - "Returns transaction by given block number and index.", - "Transaction", + 'Returns transaction by given block number and index.', + 'Transaction', [numberParam, indexParam] ), - getTransactionByHash: generateDescription("Get transaction by its hash.", "Transaction", [hashParam]), + 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", + '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", [ + getTransactionReceipt: generateDescription('Returns transaction receipt by transaction hash.', 'Receipt', [ hashParam ]), - getUncleByBlockHashAndIndex: generateDescription("Returns an uncles at given block and index.", "RichBlock", [ + getUncleByBlockHashAndIndex: generateDescription('Returns an uncles at given block and index.', 'RichBlock', [ hashParam, indexParam ]), - getUncleByBlockNumberAndIndex: generateDescription("Returns an uncles at given block and index.", "RichBlock", [ + 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", + '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", + '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" + '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"), + 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" + 'Returns protocol version encoded as a string (quotes are necessary).', + 'u64' ), - sendRawTransaction: generateDescription("Sends signed transaction, returning its hash.", "BoxFuture", [ - { name: "bytes", type: "Bytes" } + 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" } + 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" } + 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" } + 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" + '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") + peerCount: generateDescription('Returns number of peers connected to node.', 'String'), + version: generateDescription('Returns protocol version.', 'String') } }; } From 5de8089962bda7349600883219b09236e091b325 Mon Sep 17 00:00:00 2001 From: joelamouche Date: Fri, 4 Dec 2020 17:44:13 +0100 Subject: [PATCH 33/33] corrected type and removed moobeam specs --- .../src/api/bundle/spec/moonbeam.ts | 147 +++++++++--------- packages/apps-config/src/api/spec/index.ts | 4 - packages/apps-config/src/api/spec/moonbeam.ts | 74 --------- 3 files changed, 76 insertions(+), 149 deletions(-) delete mode 100644 packages/apps-config/src/api/spec/moonbeam.ts diff --git a/packages/apps-config/src/api/bundle/spec/moonbeam.ts b/packages/apps-config/src/api/bundle/spec/moonbeam.ts index d908b4536269..692b9410c998 100644 --- a/packages/apps-config/src/api/bundle/spec/moonbeam.ts +++ b/packages/apps-config/src/api/bundle/spec/moonbeam.ts @@ -1,80 +1,85 @@ // Copyright 2017-2020 @polkadot/apps-config authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { OverrideVersionedType } from '@polkadot/types/types'; +import { OverrideBundleDefinition } from "@polkadot/types/types"; // structs need to be in order /* eslint-disable sort-keys */ -export default [{ minmax: [0, undefined], - types: { - AccountId: 'EthereumAccountId', - Address: 'AccountId', - Balance: 'u128', - RefCount: 'u8', - LookupSource: 'AccountId', - Account: { - nonce: 'U256', - balance: 'u128' - }, - TransactionCondition: { - _enum: { - block: 'u64', - time: 'u64' +export default { + types: [ + { + minmax: [0, undefined], + types: { + AccountId: "EthereumAccountId", + Address: "AccountId", + Balance: "u128", + RefCount: "u8", + LookupSource: "AccountId", + Account: { + 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", + public_key: "Option", + r: "U256", + raw: "Bytes", + 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: { + ExitSucceed: "bool", + ExitError: "bool", + ExitRevert: "bool", + ExitFatal: "bool" + } + } } - }, - Transaction: { - action: 'String', - block_hash: 'Option', - block_number: 'Option', - chain_id: 'Option', - condition: 'Option', - creates: 'Option', - from: 'H160', - gas: 'U256', - gas_price: 'U256', - gas_limit: 'u64', - hash: 'H256', - input: 'Bytes', - nonce: 'U256', - public_key: 'Option', - r: 'U256', - raw: 'Bytes', - s: 'U256', - signature: 'Signature', - standard_v: 'U256', - to: 'Option', - transaction_index: 'Option', - v: 'U256', - value: 'U256' - }, - Signature: { - v: 'u64', - r: 'H256', - s: 'H256' - }, - 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' } - } }]as OverrideVersionedType[]; + ] +} as OverrideBundleDefinition; diff --git a/packages/apps-config/src/api/spec/index.ts b/packages/apps-config/src/api/spec/index.ts index 67a7c215c146..775f1da50046 100644 --- a/packages/apps-config/src/api/spec/index.ts +++ b/packages/apps-config/src/api/spec/index.ts @@ -18,7 +18,6 @@ import equilibrium from './equilibrium'; import hanonycash from './hanonycash'; import kilt from './kilt'; import kulupu from './kulupu'; -import moonbeam from './moonbeam'; import nodeTemplate from './node-template'; import nodle from './nodle'; import phala from './phala'; @@ -49,9 +48,6 @@ export default { hanonycash, kulupu, 'mashnet-node': kilt, - 'moonbase-alphanet': moonbeam, - 'moonbeam-standalone': moonbeam, - 'node-moonbeam': moonbeam, 'node-template': nodeTemplate, 'nodle-chain': nodle, 'phala-node': phala, diff --git a/packages/apps-config/src/api/spec/moonbeam.ts b/packages/apps-config/src/api/spec/moonbeam.ts deleted file mode 100644 index bb0afa5f0d4e..000000000000 --- a/packages/apps-config/src/api/spec/moonbeam.ts +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2017-2020 @polkadot/apps-config authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -// structs need to be in order -/* eslint-disable sort-keys */ - -export default { - AccountId: 'EthereumAccountId', - Address: 'AccountId', - Balance: 'u128', - RefCount: 'u8', - LookupSource: 'AccountId', - Account: { - 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', - public_key: 'Option', - r: 'U256', - raw: 'Bytes', - 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: { - ExitSucceed: 'bool', - ExitError: 'bool', - ExitRevert: 'bool', - ExitFatal: 'bool' - } } -};