Skip to content

Commit

Permalink
feat(RPC): Add getNodeInfo and getNetworkId to AEPP stamp through RPC (
Browse files Browse the repository at this point in the history
…#359)

* feat(RPC): Add getNodeInfo and getNetworkId to AEPP stamp through RPC

* fix(RPC): Add removed method to rpc

* fix(Linter): Fix traling comma
  • Loading branch information
nduchak authored Apr 24, 2019
1 parent 68f0bf6 commit 2ddeea8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
17 changes: 14 additions & 3 deletions es/account/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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
*
Expand All @@ -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: {
Expand Down
12 changes: 11 additions & 1 deletion es/chain/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
}
}
Expand Down Expand Up @@ -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
13 changes: 12 additions & 1 deletion es/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions es/rpc/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand Down

0 comments on commit 2ddeea8

Please sign in to comment.