Skip to content

Commit

Permalink
feat(Compiler): Add decode CallData by source/bytecode (#354)
Browse files Browse the repository at this point in the history
* feat(Compiler): Add decode CallData by source/bytecode

* fix(Compiler): Fix encode CallData API params
  • Loading branch information
nduchak authored Apr 23, 2019
1 parent 0599d7d commit 761f36b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions es/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ async function contractEncodeCallDataAPI (source, name, args = [], options = {})
.then(({ calldata }) => calldata)
}

async function contractDecodeCallDataByCodeAPI (bytecode, calldata, options = {}) {
return this.http
.post('/decode-calldata/bytecode', { bytecode, calldata }, options)
}

async function contractDecodeCallDataBySourceAPI (source, fn, callData, options = {}) {
return this.http
.post('/decode-calldata/source', { 'function': fn, source, calldata: callData }, options)
}

async function contractDecodeDataAPI (type, data, options = {}) {
return this.http
.post('/decode-data', { data, 'sophia-type': type }, options)
Expand Down Expand Up @@ -73,6 +83,8 @@ const ContractCompilerAPI = ContractBase.compose({
contractDecodeDataAPI,
compileContractAPI,
contractGetACI,
contractDecodeCallDataByCodeAPI,
contractDecodeCallDataBySourceAPI,
setCompilerUrl
}
})
Expand Down
27 changes: 27 additions & 0 deletions es/contract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const ContractBase = stampit({
'contractEncodeCallDataAPI',
'contractDecodeDataAPI',
'compileContractAPI',
'contractDecodeCallDataBySourceAPI',
'contractDecodeCallDataByCodeAPI',
'contractGetACI'
]
}
Expand Down Expand Up @@ -82,6 +84,31 @@ const ContractBase = stampit({
* @return {String} - Decoded contract call result
*/

/**
* Decode call data by source
* @function contractDecodeCallDataBySourceAPI
* @instance
* @abstract
* @category async
* @rtype (source: String, function: String, callData: String) => decodedResult: Promise[String]
* @param {String} source - contract source
* @param {String} function - function name
* @param {String} callData - Encoded contract call data
* @return {String} - Decoded contract call data
*/

/**
* Decode call data by bytecode
* @function contractDecodeCallDataByCodeAPI
* @instance
* @abstract
* @category async
* @rtype (code: String, callData: String) => decodedResult: Promise[String]
* @param {String} code - contract byte code
* @param {String} callData - Encoded contract call data
* @return {String} - Decoded contract call data
*/

/**
* Compile contract
* @function compileContractAPI
Expand Down

0 comments on commit 761f36b

Please sign in to comment.