Skip to content

Commit 2ddeea8

Browse files
authored
feat(RPC): Add getNodeInfo and getNetworkId to AEPP stamp through RPC (#359)
* feat(RPC): Add getNodeInfo and getNetworkId to AEPP stamp through RPC * fix(RPC): Add removed method to rpc * fix(Linter): Fix traling comma
1 parent 68f0bf6 commit 2ddeea8

File tree

4 files changed

+41
-7
lines changed

4 files changed

+41
-7
lines changed

es/account/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const DEFAULT_NETWORK_ID = `ae_mainnet`
3939
* @return {String} Signed transaction
4040
*/
4141
async function signTransaction (tx) {
42-
const networkId = this.networkId || this.nodeNetworkId || DEFAULT_NETWORK_ID
42+
const networkId = this.getNetworkId()
4343
const rlpBinaryTx = Crypto.decodeBase64Check(Crypto.assertedType(tx, 'tx'))
4444
// Prepend `NETWORK_ID` to begin of data binary
4545
const txWithNetworkId = Buffer.concat([Buffer.from(networkId), rlpBinaryTx])
@@ -48,6 +48,17 @@ async function signTransaction (tx) {
4848
return buildTx({ encodedTx: rlpBinaryTx, signatures }, TX_TYPE.signed).tx
4949
}
5050

51+
/**
52+
* Obtain networkId for signing
53+
* @instance
54+
* @category async
55+
* @rtype () => networkId: String
56+
* @return {String} NetworkId
57+
*/
58+
function getNetworkId () {
59+
return this.networkId || this.nodeNetworkId || DEFAULT_NETWORK_ID
60+
}
61+
5162
/**
5263
* Basic Account Stamp
5364
*
@@ -70,10 +81,10 @@ const Account = stampit({
7081
this.networkId = networkId
7182
}
7283
},
73-
methods: { signTransaction },
84+
methods: { signTransaction, getNetworkId },
7485
deepConf: {
7586
Ae: {
76-
methods: ['sign', 'address', 'signTransaction']
87+
methods: ['sign', 'address', 'signTransaction', 'getNetworkId']
7788
}
7889
}
7990
}, required({ methods: {

es/chain/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const Chain = Oracle.compose({
4343
Ae: {
4444
methods: [
4545
'sendTransaction', 'height', 'awaitHeight', 'poll', 'balance', 'tx',
46-
'mempool', 'topBlock', 'getTxInfo', 'txDryRun', 'getName'
46+
'mempool', 'topBlock', 'getTxInfo', 'txDryRun', 'getName', 'getNodeInfo'
4747
]
4848
}
4949
}
@@ -245,4 +245,14 @@ const Chain = Oracle.compose({
245245
* @return {Object} Result
246246
*/
247247

248+
/**
249+
* Get Node Info
250+
* @function getInfo
251+
* @instance
252+
* @abstract
253+
* @category async
254+
* @rtype () => result: Object
255+
* @return {Object} Result
256+
*/
257+
248258
export default Chain

es/node.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,26 @@ const loader = ({ url, internalUrl }) => (path, definition) => {
7474
const Node = stampit({
7575
async init ({ url = this.url, internalUrl = this.internalUrl }) {
7676
url = url.replace(/\/?$/, '/')
77-
7877
// Get swagger schema
7978
const swag = await remoteSwag(url)
8079
this.version = swag.info.version
8180
return Object.assign(this, {
81+
url,
82+
internalUrl,
8283
swag: swag,
8384
urlFor: loader({ url, internalUrl })
8485
})
8586
},
87+
methods: {
88+
getNodeInfo () {
89+
return {
90+
url: this.url,
91+
internalUrl: this.internalUrl,
92+
nodeNetworkId: this.nodeNetworkId,
93+
version: this.version
94+
}
95+
}
96+
},
8697
props: {
8798
version: null,
8899
nodeNetworkId: null

es/rpc/client.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ const RpcClient = stampit(AsyncInit, {
9494
...(R.path(['compose', 'deepConfiguration', 'Contract', 'methods'], stamp) || [])
9595
]
9696
const rpcMethods = R.fromPairs(methods.map(m => [m, post(m)]))
97-
// remove signTransaction from AEPP instance, let's go it through RPC
98-
if (stamp.compose.methods) delete stamp.compose.methods.signTransaction
97+
if (stamp.compose.methods) {
98+
// remove signTransaction and getNetworkId from AEPP instance, let's go it through RPC
99+
['signTransaction', 'getNetworkId'].forEach(m => delete stamp.compose.methods[m])
100+
}
99101
stamp.compose.methods = Object.assign(rpcMethods, stamp.compose.methods)
100102
}
101103
})

0 commit comments

Comments
 (0)