Skip to content

Commit

Permalink
wip: use calldata-js instead of http compiler call for contractCall e…
Browse files Browse the repository at this point in the history
…ncode
  • Loading branch information
mradkov committed Jul 21, 2021
1 parent 7a83d06 commit ecb793b
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
* @example import { ContractCompilerAPI } from '@aeternity/aepp-sdk'
*/

import ContractBase from './index'
import semverSatisfies from '../utils/semver-satisfies'
import Encoder from '@aeternity/aepp-calldata-js/src/Encoder'
import AsyncInit from '../utils/async-init'
import semverSatisfies from '../utils/semver-satisfies'
import genSwaggerClient from '../utils/swagger'
import ContractBase from './index'

/**
* Contract Compiler Stamp
Expand Down Expand Up @@ -82,7 +83,30 @@ export default AsyncInit.compose(ContractBase, {
arguments: args,
options: this._prepareCompilerOptions(options)
})
return calldata

// Generate using the calldata lib

// In order to be able to use the encode / decode calldata we need to have
// access to the contracts compiled abi.
const aci = await this.contractGetACI(source);

// The encoder expects the aci to be passed as array, thus this weird flex :D
const encoder = new Encoder([aci.encoded_aci]);

const testCallData = encoder.encode(
aci.encoded_aci.contract.name,
name,
args,
);

// TODO: compare the results
// console.log({
// testCallData,
// calldata,
// matching: testCallData == calldata,
// });

return testCallData; // calldata;
},
async compileContractAPI (code, options) {
this._ensureCompilerReady()
Expand Down

0 comments on commit ecb793b

Please sign in to comment.