Skip to content

Commit

Permalink
feat(Compiler): Add new compiler methods API (#875)
Browse files Browse the repository at this point in the history
* feat(Compiler): Add new compiler methods `getFateAssembler`, `getBytecodeCompilerVersion`

* feat(compiler): Fix url for `bytecode` version API. Add test's for new API. Add helper for unpacking `bytecode`

* chore(ACI): Fix Linter
  • Loading branch information
nduchak authored Jan 27, 2020
1 parent ff32d69 commit a939395
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
3 changes: 3 additions & 0 deletions es/contract/aci/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as R from 'ramda'
import { unpackTx } from '../../tx/builder'

/**
* Get function schema from contract ACI object
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion es/contract/aci/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion es/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -142,7 +152,9 @@ const ContractCompilerAPI = AsyncInit.compose(ContractBase, {
validateByteCodeAPI,
isInit,
checkCompatibility,
prepareCompilerOption
prepareCompilerOption,
getFateAssembler,
getBytecodeCompilerVersion
},
props: {
compilerVersion: null,
Expand Down
8 changes: 6 additions & 2 deletions es/contract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ const ContractBase = stampit({
'setCompilerUrl',
'getCompilerVersion',
'contractDecodeCallResultAPI',
'validateByteCodeAPI'
'validateByteCodeAPI',
'getFateAssembler',
'getBytecodeCompilerVersion'
]
}
}
Expand All @@ -63,7 +65,9 @@ const ContractBase = stampit({
setCompilerUrl: required,
getCompilerVersion: required,
contractDecodeCallResultAPI: required,
validateByteCodeAPI: required
validateByteCodeAPI: required,
getFateAssembler: required,
getBytecodeCompilerVersion: required
}
}))

Expand Down
10 changes: 10 additions & 0 deletions test/integration/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit a939395

Please sign in to comment.