Skip to content

Commit

Permalink
feat(Lima): Add support for lima (#105)
Browse files Browse the repository at this point in the history
* feat(Lima): Add support for lima

* fix(Test): FIx tests for lima. Update sdk to 5.0.0. Regenerate lock file

* feat(Lima): Fix AENS inspect command and tests. Point to node 5.0.0-rc3 and compiler 4.0.0-rc5. Change default vm/abi version for contract

* feat(AENS): Make claim transaction works with Lima

* feat(Contract): Fix contract transactions commands and test
  • Loading branch information
nduchak committed Oct 7, 2019
1 parent d0c85c1 commit f7b061a
Show file tree
Hide file tree
Showing 14 changed files with 1,156 additions and 2,285 deletions.
5 changes: 2 additions & 3 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
TAG=v5.0.0-rc.1
COMPILER_TAG=v3.2.0

TAG=v5.0.0-rc.3
COMPILER_TAG=v4.0.0-rc5
4 changes: 4 additions & 0 deletions bin/aecli-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ program
// Example: `aecli contract compile ./mycontract.contract`
program
.command('compile <file>')
.option('--backend [backend]', 'Print result in json format', utils.constant.COMPILER_BACKEND)
.description('Compile a contract')
.action(async (file, ...arguments) => await Contract.compile(file, utils.cli.getCmdFromArguments(arguments)))

Expand All @@ -52,6 +53,7 @@ program
// Example: `aecli contract encodeData ./mycontract.contract testFn 1 2`
program
.command('encodeData <source> <fn> [args...]')
.option('--backend [backend]', 'Print result in json format', utils.constant.COMPILER_BACKEND)
.description('Encode contract call data')
.action(async (source, fn, args, ...arguments) => await Contract.encodeData(source, fn, args, utils.cli.getCmdFromArguments(arguments)))

Expand All @@ -63,6 +65,7 @@ program
// Example: `aecli contract decodeData cb_asdasdasdasdasdas int`
program
.command('decodeData <data> <returnType>')
.option('--backend [backend]', 'Print result in json format', utils.constant.COMPILER_BACKEND)
.description('Decode contract data')
.action(async (data, returnType, ...arguments) => await Contract.decodeData(data, returnType, utils.cli.getCmdFromArguments(arguments)))

Expand All @@ -78,6 +81,7 @@ program
.option('--sourcePath [sourcePath]', 'Path to contract source')
.option('--code [code]', 'Compiler contract code')
.option('--fn [fn]', 'Function name')
.option('--backend [backend]', 'Print result in json format', utils.constant.COMPILER_BACKEND)
.description('Decode contract call data')
.action(async (data, ...arguments) => await Contract.decodeCallData(data, utils.cli.getCmdFromArguments(arguments)))

Expand Down
4 changes: 4 additions & 0 deletions bin/aecli-tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ program
.command('name-claim <accountId> <salt> <domain> <nonce>')
.option('-T, --ttl [ttl]', 'Validity of the transaction in number of blocks (default forever)', utils.constant.TX_TTL)
.option('-F, --fee [fee]', 'Transaction fee.')
.option('--nameFee [nameFee]', 'Name fee.', utils.constant.NAME_FEE)
.description('Build name claim transaction.')
.action(async (accountId, salt, domain, nonce, ...arguments) => await Transaction.nameClaim(accountId, salt, domain, nonce, utils.cli.getCmdFromArguments(arguments)))

Expand Down Expand Up @@ -122,6 +123,7 @@ program
.option('--deposit [deposit]', 'Deposit', 0)
.option('-G --gas [gas]', 'Amount of gas to deploy the contract', utils.constant.GAS)
.option('--vmVersion [vmVersion]', 'VM version', utils.constant.VM_VERSION)
.option('--abiVersion [abiVersion]', 'ABI version', utils.constant.DEFAULT_CONTRACT_PARAMS.abiVersion)
.description('Build contract create transaction.')
.action(async (ownerId, contractBytecode, initCallData, nonce, ...arguments) => await Transaction.contractDeploy(ownerId, contractBytecode, initCallData, nonce, utils.cli.getCmdFromArguments(arguments)))

Expand All @@ -135,6 +137,8 @@ program
.option('-T, --ttl [ttl]', 'Validity of the transaction in number of blocks (default forever)', utils.constant.TX_TTL)
.option('-F, --fee [fee]', 'Transaction fee.')
.option('-G --gas [gas]', 'Amount of gas to deploy the contract', utils.constant.GAS)
.option('--abiVersion [abiVersion]', 'VM version', utils.constant.DEFAULT_CONTRACT_PARAMS.abiVersion)
.option('--vmVersion [vmVersion]', 'ABI version', utils.constant.VM_VERSION)
.description('Build contract create transaction.')
.action(async (callerId, contractId, callData, nonce, ...arguments) => await Transaction.contractCall(callerId, contractId, callData, nonce, utils.cli.getCmdFromArguments(arguments)))

Expand Down
12 changes: 7 additions & 5 deletions bin/commands/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { GAS_PRICE } from '../utils/constant'

// ## Function which compile your `source` code
export async function compile (file, options) {
const { backend } = options
try {
const code = readFile(path.resolve(process.cwd(), file), 'utf-8')
if (!code) throw new Error('Contract file not found')
Expand All @@ -38,7 +39,7 @@ export async function compile (file, options) {

await handleApiError(async () => {
// Call `node` API which return `compiled code`
const contract = await client.compileContractAPI(code)
const contract = await client.compileContractAPI(code, { backend })
print(`Contract bytecode:
${contract}`)
})
Expand All @@ -49,6 +50,7 @@ export async function compile (file, options) {

// ## Function which compile your `source` code
export async function encodeData (source, fn, args = [], options) {
const { backend } = options
try {
const sourceCode = readFile(path.resolve(process.cwd(), source), 'utf-8')
if (!sourceCode) throw new Error('Contract file not found')
Expand All @@ -57,7 +59,7 @@ export async function encodeData (source, fn, args = [], options) {

await handleApiError(async () => {
// Call `node` API which return `compiled code`
const callData = await client.contractEncodeCallDataAPI(sourceCode, fn, args, options)
const callData = await client.contractEncodeCallDataAPI(sourceCode, fn, args, { backend })
if (options.json) {
print(JSON.stringify({ callData }))
} else {
Expand Down Expand Up @@ -91,7 +93,7 @@ export async function decodeData (data, type, options) {

// ## Function which compile your `source` code
export async function decodeCallData (data, options) {
const { sourcePath, code, fn } = options
const { sourcePath, code, fn, backend } = options
let sourceCode

if (!sourcePath && !code) throw new Error('Contract source(--sourcePath) or contract code(--code) required!')
Expand All @@ -109,8 +111,8 @@ export async function decodeCallData (data, options) {
await handleApiError(async () => {
// Call `node` API which return `compiled code`
const decoded = code
? await client.contractDecodeCallDataByCodeAPI(code, data)
: await client.contractDecodeCallDataBySourceAPI(sourceCode, fn, data)
? await client.contractDecodeCallDataByCodeAPI(code, data, backend)
: await client.contractDecodeCallDataBySourceAPI(sourceCode, fn, data, { backend })

if (options.json) {
print(JSON.stringify({ decoded }))
Expand Down
10 changes: 6 additions & 4 deletions bin/commands/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ async function namePreClaim (accountId, domain, nonce, options) {

// ## Build `nameClaim` transaction
async function nameClaim (accountId, nameSalt, domain, nonce, options) {
let { ttl, json, fee } = options
const vsn = 2
let { ttl, json, fee, nameFee } = options
const nameHash = `nm_${encodeBase58Check(Buffer.from(domain))}`

try {
Expand All @@ -106,15 +107,16 @@ async function nameClaim (accountId, nameSalt, domain, nonce, options) {
// Initialize `Ae`
const txBuilder = initOfflineTxBuilder()
const params = {
nameFee,
accountId,
nameSalt,
name: nameHash,
ttl,
nonce
}
fee = txBuilder.calculateFee(fee, TX_TYPE.nameClaim, { params })
fee = txBuilder.calculateFee(fee, TX_TYPE.nameClaim, { params, vsn })
// Build `claim` transaction's
const { tx, txObject } = txBuilder.buildTx({ ...params, fee }, TX_TYPE.nameClaim)
const { tx, txObject } = txBuilder.buildTx({ ...params, fee }, TX_TYPE.nameClaim, { vsn })

if (json) {
print({ tx, txObject })
Expand Down Expand Up @@ -276,7 +278,7 @@ async function contractDeploy (ownerId, contractByteCode, initCallData, nonce, o

// ## Build `contractCall` transaction
async function contractCall (callerId, contractId, callData, nonce, options) {
let { ttl, json, fee, gas } = options
const { ttl, json, fee, gas } = options
nonce = parseInt(nonce)
try {
// Build `call` transaction's
Expand Down
7 changes: 5 additions & 2 deletions bin/utils/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ export const PLAY_INTERVAL = 1000
// ## CONTRACT
export const GAS = 1600000 - 21000 // MAX GAS
export const DEPOSIT = 0
export const VM_VERSION = 4
export const VM_VERSION = 5
export const ABI_VERSION = 3
export const COMPILER_BACKEND = 'fate'
export const ORACLE_VM_VERSION = 0
export const GAS_PRICE = 1000000000
export const AMOUNT = 0

// ## AENS
export const NAME_TTL = 50000
export const NAME_FEE = '1000000000000000000000'
export const CLIENT_TTL = 1

// ## ACCOUNT
Expand All @@ -64,4 +67,4 @@ export const QUERY_TTL = 10
export const RESPONSE_TTL = 10

// ## Default transaction build param's
export const DEFAULT_CONTRACT_PARAMS = { vmVersion: VM_VERSION, amount: AMOUNT, deposit: DEPOSIT, gasPrice: GAS_PRICE, abiVersion: 1 }
export const DEFAULT_CONTRACT_PARAMS = { vmVersion: VM_VERSION, amount: AMOUNT, deposit: DEPOSIT, gasPrice: GAS_PRICE, abiVersion: ABI_VERSION }
2 changes: 1 addition & 1 deletion bin/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function isAvailable (name) { return name.status === 'AVAILABLE' }

// Validate `name`
export function validateName (name) {
if (R.last(name.split('.')) !== 'test') { throw new Error('AENS TLDs must end in .test') }
if (!['test', 'aet'].includes(R.last(name.split('.')))) { throw new Error('AENS TLDs must end in .test') }
}

// Grab contract descriptor by path
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
expose: [3013, 3113, 3014, 3114]
environment:
EPOCH_CONFIG: /home/aeternity/aeternity_node.yaml
command: -aecore expected_mine_rate ${EPOCH_MINE_RATE:-5000}
command: bin/aeternity console -noinput -aecore expected_mine_rate ${EPOCH_MINE_RATE:-5000}
volumes:
- ${PWD}/docker/aeternity_node_mean16.yaml:/home/aeternity/aeternity_node.yaml
- ${PWD}/docker/keys/node:/home/aeternity/node/keys
Expand Down
1 change: 1 addition & 0 deletions docker/aeternity_node_mean16.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ chain:
"1": 0
"2": 2
"3": 4
"4": 5

mining:
autostart: true
Expand Down

0 comments on commit f7b061a

Please sign in to comment.