diff --git a/es/account/index.js b/es/account/index.js index 5e2fed8dc7..3bf3842265 100644 --- a/es/account/index.js +++ b/es/account/index.js @@ -39,7 +39,7 @@ const DEFAULT_NETWORK_ID = `ae_mainnet` * @return {String} Signed transaction */ async function signTransaction (tx) { - const networkId = this.networkId || this.nodeNetworkId || DEFAULT_NETWORK_ID + const networkId = this.getNetworkId() const rlpBinaryTx = Crypto.decodeBase64Check(Crypto.assertedType(tx, 'tx')) // Prepend `NETWORK_ID` to begin of data binary const txWithNetworkId = Buffer.concat([Buffer.from(networkId), rlpBinaryTx]) @@ -48,6 +48,17 @@ async function signTransaction (tx) { return buildTx({ encodedTx: rlpBinaryTx, signatures }, TX_TYPE.signed).tx } +/** + * Obtain networkId for signing + * @instance + * @category async + * @rtype () => networkId: String + * @return {String} NetworkId + */ +function getNetworkId () { + return this.networkId || this.nodeNetworkId || DEFAULT_NETWORK_ID +} + /** * Basic Account Stamp * @@ -70,10 +81,10 @@ const Account = stampit({ this.networkId = networkId } }, - methods: { signTransaction }, + methods: { signTransaction, getNetworkId }, deepConf: { Ae: { - methods: ['sign', 'address', 'signTransaction'] + methods: ['sign', 'address', 'signTransaction', 'getNetworkId'] } } }, required({ methods: { diff --git a/es/chain/index.js b/es/chain/index.js index 2fb0c581b8..afa07db3c0 100644 --- a/es/chain/index.js +++ b/es/chain/index.js @@ -43,7 +43,7 @@ const Chain = Oracle.compose({ Ae: { methods: [ 'sendTransaction', 'height', 'awaitHeight', 'poll', 'balance', 'tx', - 'mempool', 'topBlock', 'getTxInfo', 'txDryRun', 'getName' + 'mempool', 'topBlock', 'getTxInfo', 'txDryRun', 'getName', 'getNodeInfo' ] } } @@ -245,4 +245,14 @@ const Chain = Oracle.compose({ * @return {Object} Result */ +/** + * Get Node Info + * @function getInfo + * @instance + * @abstract + * @category async + * @rtype () => result: Object + * @return {Object} Result + */ + export default Chain diff --git a/es/node.js b/es/node.js index 60c24b6b21..844fe9596b 100644 --- a/es/node.js +++ b/es/node.js @@ -74,15 +74,26 @@ const loader = ({ url, internalUrl }) => (path, definition) => { const Node = stampit({ async init ({ url = this.url, internalUrl = this.internalUrl }) { url = url.replace(/\/?$/, '/') - // Get swagger schema const swag = await remoteSwag(url) this.version = swag.info.version return Object.assign(this, { + url, + internalUrl, swag: swag, urlFor: loader({ url, internalUrl }) }) }, + methods: { + getNodeInfo () { + return { + url: this.url, + internalUrl: this.internalUrl, + nodeNetworkId: this.nodeNetworkId, + version: this.version + } + } + }, props: { version: null, nodeNetworkId: null diff --git a/es/rpc/client.js b/es/rpc/client.js index c4b8d466b9..fb2baabfbe 100644 --- a/es/rpc/client.js +++ b/es/rpc/client.js @@ -94,8 +94,10 @@ const RpcClient = stampit(AsyncInit, { ...(R.path(['compose', 'deepConfiguration', 'Contract', 'methods'], stamp) || []) ] const rpcMethods = R.fromPairs(methods.map(m => [m, post(m)])) - // remove signTransaction from AEPP instance, let's go it through RPC - if (stamp.compose.methods) delete stamp.compose.methods.signTransaction + if (stamp.compose.methods) { + // remove signTransaction and getNetworkId from AEPP instance, let's go it through RPC + ['signTransaction', 'getNetworkId'].forEach(m => delete stamp.compose.methods[m]) + } stamp.compose.methods = Object.assign(rpcMethods, stamp.compose.methods) } })