diff --git a/es/contract/aci/helpers.js b/es/contract/aci/helpers.js index 794b2b63c1..3a37b6a107 100644 --- a/es/contract/aci/helpers.js +++ b/es/contract/aci/helpers.js @@ -1,4 +1,5 @@ import * as R from 'ramda' +import { unpackTx } from '../../tx/builder' /** * Get function schema from contract ACI object @@ -81,3 +82,5 @@ const parseArguments = (aciArgs = []) => (args) => ({ opt: args.length > aciArgs.length ? R.last(args) : {}, args: Object.values(args).slice(0, aciArgs.length) }) + +export const unpackByteCode = (bytecode) => unpackTx(bytecode, false, 'cb').tx diff --git a/es/contract/aci/index.js b/es/contract/aci/index.js index 8c48537e97..74ec4a9b67 100644 --- a/es/contract/aci/index.js +++ b/es/contract/aci/index.js @@ -76,7 +76,7 @@ async function prepareArgsForEncode (aci, params) { * Also you can call contract like: await contractIns.methods.setState(123, options) * Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is stateful or not */ -async function getContractInstance (source, { aci, contractAddress, filesystem = {}, forceCodeCheck = false, opt } = {}) { +async function getContractInstance (source, { aci, contractAddress, filesystem = {}, forceCodeCheck = true, opt } = {}) { aci = aci || await this.contractGetACI(source, { filesystem }) const defaultOptions = { skipArgsConvert: false, diff --git a/es/contract/compiler.js b/es/contract/compiler.js index 137cd8b0e0..df0d5bd99e 100644 --- a/es/contract/compiler.js +++ b/es/contract/compiler.js @@ -86,6 +86,16 @@ async function contractGetACI (code, options = {}) { return this.http.post('/aci', { code, options: this.prepareCompilerOption(options) }, options) } +async function getFateAssembler (bytecode, options = {}) { + this.isInit() + return this.http.post('/fate-assembler', { bytecode, options: this.prepareCompilerOption(options) }, options) +} + +async function getBytecodeCompilerVersion (bytecode, options = {}) { + this.isInit() + return this.http.post('/compiler-version', { bytecode, options: this.prepareCompilerOption(options) }, options) +} + async function setCompilerUrl (url, { forceCompatibility = false } = {}) { this.http.changeBaseUrl(url) this.compilerVersion = await this.getCompilerVersion().catch(e => null) @@ -142,7 +152,9 @@ const ContractCompilerAPI = AsyncInit.compose(ContractBase, { validateByteCodeAPI, isInit, checkCompatibility, - prepareCompilerOption + prepareCompilerOption, + getFateAssembler, + getBytecodeCompilerVersion }, props: { compilerVersion: null, diff --git a/es/contract/index.js b/es/contract/index.js index aed23668f1..71c296deea 100644 --- a/es/contract/index.js +++ b/es/contract/index.js @@ -50,7 +50,9 @@ const ContractBase = stampit({ 'setCompilerUrl', 'getCompilerVersion', 'contractDecodeCallResultAPI', - 'validateByteCodeAPI' + 'validateByteCodeAPI', + 'getFateAssembler', + 'getBytecodeCompilerVersion' ] } } @@ -63,7 +65,9 @@ const ContractBase = stampit({ setCompilerUrl: required, getCompilerVersion: required, contractDecodeCallResultAPI: required, - validateByteCodeAPI: required + validateByteCodeAPI: required, + getFateAssembler: required, + getBytecodeCompilerVersion: required } })) diff --git a/test/integration/contract.js b/test/integration/contract.js index 4ad76c4930..7ee9190024 100644 --- a/test/integration/contract.js +++ b/test/integration/contract.js @@ -317,6 +317,16 @@ describe('Contract', function () { prefix.should.be.equal('cb') isString.should.be.equal(true) }) + it('Get FATE assembler', async () => { + const result = await contract.getFateAssembler(bytecode) + result.should.be.a('object') + const assembler = result['fate-assembler'] + assembler.should.be.a('string') + }) + it('Get compiler version from bytecode', async () => { + const version = await contract.getBytecodeCompilerVersion(bytecode) + console.log(version) + }) it('get contract ACI', async () => { const aci = await contract.contractGetACI(identityContract) aci.should.have.property('interface')