Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Compiler): Add new compiler methods API #875

Merged
merged 5 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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