Skip to content

Commit

Permalink
refactor(contract)!: remove compileContractAPI
Browse files Browse the repository at this point in the history
use sdk.compilerApi.compileContract instead
  • Loading branch information
davidyuk committed Jan 24, 2022
1 parent 23ada71 commit 5ae9c62
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 36 deletions.
12 changes: 6 additions & 6 deletions src/ae/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async function contractDeploy (code, source, params, options) {
* @function
* @alias module:@aeternity/aepp-sdk/es/ae/contract
* @category async
* @param {String} source Contract sourece code
* @param {String} code Contract source code
* @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit)
* @param {Object} [options.filesystem={}] Contract external namespaces map*
* @return {Promise<Object>} Result object
Expand All @@ -135,13 +135,13 @@ async function contractDeploy (code, source, params, options) {
* encodeCall: (fnName, args = []) => Prepare callData
* }
*/
async function contractCompile (source, options = {}) {
async function contractCompile (code, options = {}) {
const opt = { ...this.Ae.defaults, ...options }
const bytecode = await this.compileContractAPI(source, options)
const { bytecode } = await this.compilerApi.compileContract({ code, options })
return Object.freeze({
encodeCall: (name, args) => this.contractEncodeCallDataAPI(source, name, args, opt),
deploy: (init, options) => this.contractDeploy(bytecode, source, init, { ...opt, ...options }),
deployStatic: (init, options) => this.contractCallStatic(source, null, 'init', init, {
encodeCall: (name, args) => this.contractEncodeCallDataAPI(code, name, args, opt),
deploy: (init, options) => this.contractDeploy(bytecode, code, init, { ...opt, ...options }),
deployStatic: (init, options) => this.contractCallStatic(code, null, 'init', init, {
...opt,
...options,
bytecode
Expand Down
5 changes: 0 additions & 5 deletions src/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,6 @@ export default AsyncInit.compose(ContractBase, {
options
})
return calldata
},
async compileContractAPI (code, options) {
this._ensureCompilerReady()
const { bytecode } = await this.compilerApi.compileContract({ code, options })
return bytecode
}
},
props: {
Expand Down
14 changes: 0 additions & 14 deletions src/contract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { required } from '@stamp/required'
const ContractBase = stampit(required({
methods: {
contractEncodeCallDataAPI: required,
compileContractAPI: required,
setCompilerUrl: required,
getCompilerVersion: required
}
Expand All @@ -61,19 +60,6 @@ const ContractBase = stampit(required({
* @return {String} - Contract encoded data
*/

/**
* Compile contract
* @function compileContractAPI
* @instance
* @abstract
* @category async
* @rtype (code: String, options?: Object) => compiledContract: Object
* @param {String} code - Contract source code
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @return {Object} Object which contain bytecode of contract
*/

/**
* Set compiler url
* @function setCompilerUrl
Expand Down
21 changes: 10 additions & 11 deletions test/integration/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,20 +286,19 @@ describe('Contract', function () {
let bytecode

it('compile', async () => {
bytecode = await sdk.compileContractAPI(identityContract)
const prefix = bytecode.slice(0, 2)
const isString = typeof bytecode === 'string'
prefix.should.be.equal('cb')
isString.should.be.equal(true)
bytecode = (await sdk.compilerApi.compileContract({ code: identityContract })).bytecode
expect(bytecode).to.be.a('string')
expect(bytecode.split('_')[0]).to.be.equal('cb')
})

it('throws clear exception if compile broken contract', async () => {
await expect(sdk.compileContractAPI(
'contract Foo =\n' +
' entrypoint getArg(x : bar) = x\n' +
' entrypoint getArg(x : int) = baz\n' +
' entrypoint getArg1(x : int) = baz\n'
)).to.be.rejectedWith(
await expect(sdk.compilerApi.compileContract({
code:
'contract Foo =\n' +
' entrypoint getArg(x : bar) = x\n' +
' entrypoint getArg(x : int) = baz\n' +
' entrypoint getArg1(x : int) = baz\n'
})).to.be.rejectedWith(
'compile error:\n' +
'type_error:3:3: Duplicate definitions of getArg at\n' +
' - line 2, column 3\n' +
Expand Down

0 comments on commit 5ae9c62

Please sign in to comment.