Skip to content

Commit

Permalink
chore: drop aevm support and backend (compiler) option
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed May 5, 2021
1 parent f416cdd commit 6eb702d
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 62 deletions.
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Please tell us about your environment:**

- Node Version: v0.0.0
- Protocol Version: 1
- Compiler version: v0.0.0
- VM Version: aevm | fate
- VM Version: fate | fate2
- SDK Version: v0.0.0
- Python version: v3.7.0

Expand Down
4 changes: 1 addition & 3 deletions src/ae/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ async function _handleCallError (source, name, result) {
* @param {Array} args Argument's for call
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem={}] Contract external namespaces map
* @param {Object} [options.backend='fate'] Compiler backend
* @return {Promise<String>}
* @return {Promise<String>}
*/
async function contractEncodeCall (source, name, args, options) {
return this.contractEncodeCallDataAPI(source, name, args, options)
Expand Down Expand Up @@ -252,7 +251,6 @@ async function contractDeploy (code, source, initState = [], options = {}) {
* @param {String} source Contract sourece code
* @param {Object} [options={}] Transaction options (fee, ttl, gas, amount, deposit)
* @param {Object} [options.filesystem={}] Contract external namespaces map* @return {Promise<Object>} Result object
* @param {Object} [options.backend='fate'] Contract backend version (aevm|fate)
* @return {Promise<Object>} Result object
* @example
* const compiled = await client.contractCompile(SOURCE_CODE)
Expand Down
14 changes: 5 additions & 9 deletions src/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import ContractBase from './index'
import semverSatisfies from '../utils/semver-satisfies'
import AsyncInit from '../utils/async-init'
import genSwaggerClient from '../utils/swagger'
import { VM_TYPE } from '../tx/builder/schema'

/**
* Contract Compiler Stamp
Expand Down Expand Up @@ -67,8 +66,8 @@ export default AsyncInit.compose(ContractBase, {
_ensureCompilerReady () {
if (!this._compilerApi) throw new Error('Compiler is not ready')
},
_prepareCompilerOptions ({ backend = this.compilerOptions.backend, filesystem = {} } = {}) {
return { backend, fileSystem: filesystem }
_prepareCompilerOptions ({ filesystem = {} } = {}) {
return { fileSystem: filesystem }
},
getCompilerVersion () {
this._ensureCompilerReady()
Expand Down Expand Up @@ -96,9 +95,9 @@ export default AsyncInit.compose(ContractBase, {
this._ensureCompilerReady()
return this._compilerApi.generateACI({ code, options: this._prepareCompilerOptions(options) })
},
contractDecodeCallDataByCodeAPI (bytecode, calldata, backend = this.compilerOptions.backend) {
contractDecodeCallDataByCodeAPI (bytecode, calldata) {
this._ensureCompilerReady()
return this._compilerApi.decodeCalldataBytecode({ bytecode, calldata, backend })
return this._compilerApi.decodeCalldataBytecode({ bytecode, calldata })
},
contractDecodeCallDataBySourceAPI (source, fn, callData, options) {
this._ensureCompilerReady()
Expand Down Expand Up @@ -141,10 +140,7 @@ export default AsyncInit.compose(ContractBase, {
}
},
props: {
compilerVersion: null,
compilerOptions: {
backend: VM_TYPE.FATE
}
compilerVersion: null
}
})

Expand Down
6 changes: 0 additions & 6 deletions src/contract/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const ContractBase = stampit(required({
* @param {String} source - Contract source code
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @param {Object} [options.backend] Contract vm (default: fate)
* @return {Object} - Contract aci object
*/

Expand All @@ -77,7 +76,6 @@ const ContractBase = stampit(required({
* @param {Array} args - Function argument's
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @param {Object} [options.backend] Contract vm (default: fate)
* @return {String} - Contract encoded data
*/

Expand All @@ -94,7 +92,6 @@ const ContractBase = stampit(required({
* @param {String} callResult - contract call result status('ok', 'revert', ...)
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @param {Object} [options.backend] Contract vm (default: fate)
* @return {String} - Decoded contract call result
*/

Expand All @@ -110,7 +107,6 @@ const ContractBase = stampit(required({
* @param {String} callData - Encoded contract call data
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @param {Object} [options.backend] Contract vm (default: fate)
* @return {String} - Decoded contract call data
*/

Expand All @@ -123,7 +119,6 @@ const ContractBase = stampit(required({
* @rtype (code: String, callData: String) => decodedResult: Promise[String]
* @param {String} code - contract byte code
* @param {String} callData - Encoded contract call data
* @param {String} backend - Contract vm (default: fate)
* @return {String} - Decoded contract call data
*/

Expand All @@ -137,7 +132,6 @@ const ContractBase = stampit(required({
* @param {String} code - Contract source code
* @param {Object} [options={}] Options
* @param {Object} [options.filesystem] Contract external namespaces map
* @param {Object} [options.backend] Contract vm (default: fate)
* @return {Object} Object which contain bytecode of contract
*/

Expand Down
16 changes: 1 addition & 15 deletions src/tx/builder/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ import {
NAME_FEE,
NAME_FEE_BID_INCREMENT,
NAME_BID_TIMEOUTS,
FATE_ABI,
VM_TYPE, NAME_ID_KEY
NAME_ID_KEY
} from './schema'
import { ceil } from '../../utils/bignumber'

Expand Down Expand Up @@ -339,19 +338,6 @@ export function computeAuctionEndBlock (domain, claimHeight) {
])(domain.replace('.chain', '').length).toString(10)
}

/**
* Get contract backend by abiVersion
* @function
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
* @param {Object} { abiVersion } abiVersion Transaction abiVersion
* @return {String} Backend
*/
export function getContractBackendFromTx ({ abiVersion } = {}) {
return FATE_ABI.includes(parseInt(abiVersion))
? VM_TYPE.FATE
: VM_TYPE.AEVM
}

/**
* Is name accept going to auction
* @function
Expand Down
5 changes: 2 additions & 3 deletions src/tx/builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import {
buildPointers,
encode,
decode,
buildHash,
getContractBackendFromTx
buildHash
} from './helpers'
import { toBytes } from '../../utils/bytes'
import * as mpt from '../../utils/mptree'
Expand Down Expand Up @@ -253,7 +252,7 @@ export function calculateMinFee (txType, { gas = 0, params, vsn }) {
function buildFee (txType, { params, gas = 0, multiplier, vsn }) {
const { rlpEncoded: txWithOutFee } = buildTx({ ...params }, txType, { vsn })
const txSize = txWithOutFee.length
return TX_FEE_BASE_GAS(txType, { backend: getContractBackendFromTx(params) })
return TX_FEE_BASE_GAS(txType)
.plus(TX_FEE_OTHER_GAS(txType)({ txSize, relativeTtl: getOracleRelativeTtl(params, txType) }))
.times(multiplier)
}
Expand Down
7 changes: 2 additions & 5 deletions src/tx/builder/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,6 @@ export const ABI_VERSIONS = {
FATE: 3
}

export const VM_TYPE = { FATE: 'fate', AEVM: 'aevm' }
export const FATE_ABI = [3]

// First abi/vm by default
export const VM_ABI_MAP_ROMA = {
[TX_TYPE.contractCreate]: { vmVersion: [VM_VERSIONS.SOPHIA], abiVersion: [ABI_VERSIONS.SOPHIA] },
Expand Down Expand Up @@ -372,7 +369,7 @@ export const DEFAULT_FEE = 20000
export const KEY_BLOCK_INTERVAL = 3

// MAP WITH FEE CALCULATION https://github.com/aeternity/protocol/blob/master/consensus/consensus.md#gas
export const TX_FEE_BASE_GAS = (txType, { backend = VM_TYPE.FATE }) => {
export const TX_FEE_BASE_GAS = (txType) => {
switch (txType) {
// case TX_TYPE.gaMeta: // TODO investigate MetaTx calculation
case TX_TYPE.gaAttach:
Expand All @@ -381,7 +378,7 @@ export const TX_FEE_BASE_GAS = (txType, { backend = VM_TYPE.FATE }) => {
// Todo Implement meta tx fee calculation
case TX_TYPE.gaMeta:
case TX_TYPE.contractCall:
return BigNumber((backend === VM_TYPE.FATE ? 12 : 30) * BASE_GAS)
return BigNumber(12 * BASE_GAS)
default:
return BigNumber(BASE_GAS)
}
Expand Down
16 changes: 8 additions & 8 deletions src/tx/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import ChainNode from '../chain/node'
import Tx from './'

import { buildTx, calculateFee } from './builder'
import { ABI_VERSIONS, MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE, VM_TYPE, TX_TTL } from './builder/schema'
import { ABI_VERSIONS, MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE, TX_TTL } from './builder/schema'
import { buildContractId } from './builder/helpers'
import { TxObject } from './tx-object'

Expand Down Expand Up @@ -147,7 +147,7 @@ async function nameRevokeTx ({ accountId, nameId }) {
return tx
}

async function contractCreateTx ({ ownerId, code, vmVersion, abiVersion, deposit, amount, gas, gasPrice = MIN_GAS_PRICE, callData, backend }) {
async function contractCreateTx ({ ownerId, code, vmVersion, abiVersion, deposit, amount, gas, gasPrice = MIN_GAS_PRICE, callData }) {
// Get VM_ABI version
const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, R.head(arguments))
// Calculate fee, get absolute ttl (ttl + height), get account nonce
Expand All @@ -164,7 +164,7 @@ async function contractCreateTx ({ ownerId, code, vmVersion, abiVersion, deposit
: this.api.postContractCreate(R.merge(R.head(arguments), { nonce, ttl, fee: parseInt(fee), gas: parseInt(gas), gasPrice, vmVersion: ctVersion.vmVersion, abiVersion: ctVersion.abiVersion }))
}

async function contractCallTx ({ callerId, contractId, abiVersion, amount, gas, gasPrice = MIN_GAS_PRICE, callData, backend }) {
async function contractCallTx ({ callerId, contractId, abiVersion, amount, gas, gasPrice = MIN_GAS_PRICE, callData }) {
const ctVersion = this.getVmVersion(TX_TYPE.contractCall, R.head(arguments))
// Calculate fee, get absolute ttl (ttl + height), get account nonce
const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.contractCall, { senderId: callerId, ...R.head(arguments), gasPrice, abiVersion: ctVersion.abiVersion })
Expand Down Expand Up @@ -396,7 +396,7 @@ async function channelSnapshotSoloTx ({ channelId, fromId, payload }) {
return tx
}

async function gaAttachTx ({ ownerId, code, vmVersion, abiVersion, authFun, gas, gasPrice = MIN_GAS_PRICE, callData, backend }) {
async function gaAttachTx ({ ownerId, code, vmVersion, abiVersion, authFun, gas, gasPrice = MIN_GAS_PRICE, callData }) {
// Get VM_ABI version
const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, R.head(arguments))
// Calculate fee, get absolute ttl (ttl + height), get account nonce
Expand All @@ -416,18 +416,18 @@ async function gaAttachTx ({ ownerId, code, vmVersion, abiVersion, authFun, gas,
*
* @param {string} txType Type of transaction
* @param {object} vmAbi Object with vm and abi version fields
* @return {object} Object with vm/abi version ({ vmVersion: number, abiVersion: number, backend: string })
* @return {object} Object with vm/abi version ({ vmVersion: number, abiVersion: number })
*/
function getVmVersion (txType, { vmVersion, abiVersion, backend } = {}) {
function getVmVersion (txType, { vmVersion, abiVersion } = {}) {
const { consensusProtocolVersion } = this.getNodeInfo()
const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion]
if (!supportedProtocol) throw new Error('Not supported consensus protocol version')
const protocolForTX = supportedProtocol[txType]
if (!protocolForTX) throw new Error('Not supported tx type')

const ctVersion = {
abiVersion: abiVersion !== undefined ? abiVersion : backend === VM_TYPE.AEVM ? protocolForTX.abiVersion[1] : backend === VM_TYPE.FATE ? protocolForTX.abiVersion[0] : protocolForTX.abiVersion[0],
vmVersion: vmVersion !== undefined ? vmVersion : backend === VM_TYPE.AEVM ? protocolForTX.vmVersion[1] : backend === VM_TYPE.FATE ? protocolForTX.vmVersion[0] : protocolForTX.vmVersion[0]
abiVersion: abiVersion || protocolForTX.abiVersion[0],
vmVersion: vmVersion || protocolForTX.vmVersion[0]
}
if (protocolForTX.vmVersion.length && !R.contains(ctVersion.vmVersion, protocolForTX.vmVersion)) throw new Error(`VM VERSION ${ctVersion.vmVersion} do not support by this node. Supported: [${protocolForTX.vmVersion}]`)
if (protocolForTX.abiVersion.length && !R.contains(ctVersion.abiVersion, protocolForTX.abiVersion)) throw new Error(`ABI VERSION ${ctVersion.abiVersion} do not support by this node. Supported: [${protocolForTX.abiVersion}]`)
Expand Down
11 changes: 0 additions & 11 deletions test/integration/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -637,17 +637,6 @@ describe('Contract', function () {
result.should.have.property('returnType')
result.callerId.should.be.equal(onAccount)
})
it('Can deploy/call using AEVM', async () => {
await contractObject.compile({ backend: 'aevm' })
const deployStatic = await contractObject.methods.init.get('123', 1, 'hahahaha', { backend: 'aevm' })
deployStatic.should.be.an('object')
deployed = await contractObject.methods.init.send('123', 1, 'hahahaha', { backend: 'aevm' })
deployed.should.be.an('object')
const { result } = await contractObject.methods.intFn(123, { backend: 'aevm' })
result.should.have.property('gasUsed')
result.should.have.property('returnType')
await contractObject.compile()
})
it('Deploy contract before compile', async () => {
contractObject.compiled = null
await contractObject.methods.init('123', 1, 'hahahaha')
Expand Down

0 comments on commit 6eb702d

Please sign in to comment.