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

Release 4.6.0 #636

Merged
merged 11 commits into from
Aug 28, 2019
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
TAG=v4.0.0
TAG=v5.0.0-rc.1
COMPILER_TAG=v3.2.0
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
# [4.6.0](https://github.com/aeternity/aepp-sdk-js/compare/2.4.0...4.6.0) (2019-08-28)



### Bug Fixes

* **Compiler:** Fix `forceCompatibility` option ([26beba8](https://github.com/aeternity/aepp-sdk-js/commit/26beba8))


### Features

* **Lima**: add preliminary support for lima
* **ACI/Contract:** Implement static-call for deploy transaction for ACI methods/Contract low lvl API ([#630](https://github.com/aeternity/aepp-sdk-js/issues/630)) ([5b7eeb4](https://github.com/aeternity/aepp-sdk-js/commit/5b7eeb4))


### Notes

**GA support has been disabled until further notice due to node compatibility issues**
**This version support aeternity node up to 5.0.0-rc.1**



## [4.5.1](https://github.com/aeternity/aepp-sdk-js/compare/2.4.0...4.5.1) (2019-08-22)


Expand Down
5 changes: 3 additions & 2 deletions es/ae/aepp.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import Aens from './aens'
import Rpc from '../rpc/client'
import { ContractAPI } from './contract'
import Oracle from './oracle'
import GeneralizeAccount from '../contract/ga'
// Todo Enable GA
// import GeneralizeAccount from '../contract/ga'

/**
* Aepp Stamp
Expand All @@ -41,6 +42,6 @@ import GeneralizeAccount from '../contract/ga'
* @param {Object} [options={}] - Initializer object
* @return {Object} Aepp instance
*/
const Aepp = Ae.compose(ContractAPI, Aens, Oracle, GeneralizeAccount, Rpc)
const Aepp = Ae.compose(ContractAPI, Aens, Oracle, Rpc)

export default Aepp
43 changes: 33 additions & 10 deletions es/ae/contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ async function contractDecodeData (source, fn, callValue, callResult, options) {
* @param {Array} args Argument's for call function
* @param {Object} options [options={}] Options
* @param {String} top [options.top] Block hash on which you want to call contract
* @param bytecode
* @param {String} options [options.options] Transaction options (fee, ttl, gas, amount, deposit)
* @return {Promise<Object>} Result object
* @example
Expand All @@ -107,25 +108,45 @@ async function contractDecodeData (source, fn, callValue, callResult, options) {
* decode: (type) => Decode call result
* }
*/
async function contractCallStatic (source, address, name, args = [], { top, options = {} } = {}) {
async function contractCallStatic (source, address, name, args = [], { top, options = {}, bytecode } = {}) {
const opt = R.merge(this.Ae.defaults, options)
const callerId = opt.onAccount
? await this.address(opt)
: await this.address().catch(e => opt.dryRunAccount.pub)

// Prepare call-data
const callData = await this.contractEncodeCall(source, name, args)

// Get block hash by height
if (top && !isNaN(top)) {
top = (await this.getKeyBlock(top)).hash
}
// Prepare nonce
const nonce = top ? (await this.getAccount(callerId, { hash: top })).nonce + 1 : undefined

// Prepare `call` transaction
const tx = await this.contractCallTx(R.merge(opt, {
callerId,
contractId: address,
callData: await this.contractEncodeCall(source, name, args),
nonce: top ? (await this.getAccount(callerId, { hash: top })).nonce + 1 : undefined
}))
if (name === 'init') {
// Prepare deploy transaction
const { tx } = await this.contractCreateTx(R.merge(opt, {
callData,
code: bytecode,
ownerId: callerId,
nonce
}))
return this.dryRunContractTx(tx, callerId, source, name, { ...opt, top })
} else {
// Prepare `call` transaction
const tx = await this.contractCallTx(R.merge(opt, {
callerId,
contractId: address,
callData,
nonce
}))
return this.dryRunContractTx(tx, callerId, source, name, { ...opt, top })
}
}

async function dryRunContractTx (tx, callerId, source, name, opt = {}) {
const { top } = opt
// Dry-run
const dryRunAmount = BigNumber(opt.dryRunAccount.amount).gt(BigNumber(opt.amount || 0)) ? opt.dryRunAccount.amount : opt.amount
const dryRunAccount = {
Expand All @@ -142,7 +163,7 @@ async function contractCallStatic (source, address, name, args = [], { top, opti
}
return {
result: callObj,
decode: () => this.contractDecodeData(source, name, returnValue, returnType, options)
decode: () => this.contractDecodeData(source, name, returnValue, returnType, opt)
}
}

Expand Down Expand Up @@ -261,7 +282,8 @@ async function contractCompile (source, options = {}) {
const bytecode = await this.compileContractAPI(source, options)
return Object.freeze(Object.assign({
encodeCall: async (name, args) => this.contractEncodeCall(source, name, args),
deploy: async (init, options = {}) => this.contractDeploy(bytecode, source, init, options)
deploy: async (init, options = {}) => this.contractDeploy(bytecode, source, init, options),
deployStatic: async (init, options = {}) => this.contractCallStatic(source, null, 'init', init, { bytecode, top: options.top, options })
}, { bytecode }))
}

Expand Down Expand Up @@ -302,6 +324,7 @@ export const ContractAPI = Ae.compose(ContractBase, ContractACI, {
contractCall,
contractEncodeCall,
contractDecodeData,
dryRunContractTx,
handleCallError
},
deepProps: {
Expand Down
20 changes: 12 additions & 8 deletions es/ae/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,16 @@ import { BigNumber } from 'bignumber.js'
*/
async function send (tx, options = {}) {
const opt = R.merge(this.Ae.defaults, options)
const { contractId: gaId, authFun } = await this.getAccount(await this.address(opt))
const signed = gaId
? await this.signUsingGA(tx, { ...opt, authFun })
: await this.signTransaction(tx, options)
return this.sendTransaction(signed, options)
// Todo Enable GA
// const { contractId: gaId, authFun } = await this.getAccount(await this.address(opt))
// const signed = gaId
// ? await this.signUsingGA(tx, { ...opt, authFun })
const signed = await this.signTransaction(tx, opt)
return this.sendTransaction(signed, opt)
}

// Todo Enable GA
// eslint-disable-next-line no-unused-vars
async function signUsingGA (tx, options = {}) {
const { authData, authFun } = options
return this.createMetaTx(tx, authData, authFun, options)
Expand Down Expand Up @@ -132,9 +135,10 @@ function destroyInstance () {
* @return {Object} Ae instance
*/
const Ae = stampit(Tx, Account, Chain, {
methods: { send, spend, transferFunds, destroyInstance, signUsingGA },
deepProps: { Ae: { defaults: {} } },
deepConfiguration: { Ae: { methods: ['signUsingGA'] } }
methods: { send, spend, transferFunds, destroyInstance },
deepProps: { Ae: { defaults: {} } }
// Todo Enable GA
// deepConfiguration: { Ae: { methods: ['signUsingGA'] } }
})

export default Ae
5 changes: 3 additions & 2 deletions es/ae/universal.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import Chain from '../chain/node'
import Aens from './aens'
import Transaction from '../tx/tx'
import Oracle from './oracle'
import GeneralizeAccount from '../contract/ga'
// Todo Enable GA
// import GeneralizeAccount from '../contract/ga'
import Accounts from '../accounts'
import Contract from './contract'
import NodePool from '../node-pool'
Expand All @@ -43,7 +44,7 @@ import NodePool from '../node-pool'
* @param {Object} [options={}] - Initializer object
* @return {Object} Universal instance
*/
export const Universal = Ae.compose(Accounts, Chain, NodePool, Transaction, Aens, Contract, Oracle, GeneralizeAccount, {
export const Universal = Ae.compose(Accounts, Chain, NodePool, Transaction, Aens, Contract, Oracle, {
init () {},
props: { process: {} }
})
Expand Down
5 changes: 3 additions & 2 deletions es/ae/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import * as R from 'ramda'
import Tx from '../tx/tx'
import Contract from './contract'
import NodePool from '../node-pool'
import GeneralizeAccount from '../contract/ga'
// Todo Enable GA
// import GeneralizeAccount from '../contract/ga'

const contains = R.flip(R.contains)
const isTxMethod = contains(Tx.compose.deepConfiguration.Ae.methods)
Expand Down Expand Up @@ -131,7 +132,7 @@ async function rpcAddress ({ params, session }) {
onContract: confirm
})
*/
const Wallet = Ae.compose(Accounts, Chain, NodePool, Tx, Contract, GeneralizeAccount, Rpc, {
const Wallet = Ae.compose(Accounts, Chain, NodePool, Tx, Contract, Rpc, {
init ({ onTx = this.onTx, onChain = this.onChain, onAccount = this.onAccount, onContract = this.onContract }, { stamp }) {
this.onTx = onTx
this.onChain = onChain
Expand Down
30 changes: 22 additions & 8 deletions es/contract/aci/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ export function getFunctionACI (aci, name) {
* @return {Object} Contract instance methods
*/
export const buildContractMethods = (instance) => () => ({
...instance.aci ? {
init () {
const { arguments: aciArgs } = getFunctionACI(instance.aci, 'init')
const { opt, args } = parseArguments(aciArgs)(arguments)
return instance.deploy(args, opt)
}
} : {},
...instance.aci
? instance
.aci
Expand Down Expand Up @@ -60,7 +53,28 @@ export const buildContractMethods = (instance) => () => ({
}),
{}
)
: {}
: {},
...instance.aci ? {
init: Object.assign(
function () {
const { arguments: aciArgs } = getFunctionACI(instance.aci, 'init')
const { opt, args } = parseArguments(aciArgs)(arguments)
return instance.deploy(args, opt)
},
{
get () {
const { arguments: aciArgs } = getFunctionACI(instance.aci, 'init')
const { opt, args } = parseArguments(aciArgs)(arguments)
return instance.deploy(args, { ...opt, callStatic: true })
},
send () {
const { arguments: aciArgs } = getFunctionACI(instance.aci, 'init')
const { opt, args } = parseArguments(aciArgs)(arguments)
return instance.deploy(args, { ...opt, callStatic: false })
}
}
)
} : {}
})

const parseArguments = (aciArgs = []) => (args) => ({
Expand Down
15 changes: 12 additions & 3 deletions es/contract/aci/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,22 @@ const call = ({ client, instance }) => async (fn, params = [], options = {}) =>
const deploy = ({ client, instance }) => async (init = [], options = {}) => {
const opt = R.merge(instance.options, options)
const fnACI = getFunctionACI(instance.aci, 'init')
const source = opt.source || instance.source

if (!instance.compiled) await instance.compile()
init = !opt.skipArgsConvert ? await prepareArgsForEncode(fnACI, init) : init

const { owner, transaction, address, createdAt, result, rawTx } = await client.contractDeploy(instance.compiled, opt.source || instance.source, init, opt)
instance.deployInfo = { owner, transaction, address, createdAt, result, rawTx }
return instance.deployInfo
if (opt.callStatic) {
return client.contractCallStatic(source, null, 'init', init, {
top: opt.top,
options: opt,
bytecode: instance.compiled
})
} else {
const { owner, transaction, address, createdAt, result, rawTx } = await client.contractDeploy(instance.compiled, opt.source || instance.source, init, opt)
instance.deployInfo = { owner, transaction, address, createdAt, result, rawTx }
return instance.deployInfo
}
}

const compile = ({ client, instance }) => async () => {
Expand Down
12 changes: 6 additions & 6 deletions es/contract/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ async function contractGetACI (code, options = {}) {
return this.http.post('/aci', { code, options }, options)
}

async function setCompilerUrl (url) {
async function setCompilerUrl (url, { forceCompatibility } = {}) {
this.http.changeBaseUrl(url)
this.compilerVersion = null
await this.checkCompatibility()
await this.checkCompatibility({ forceCompatibility })
}

async function checkCompatibility (force = false) {
async function checkCompatibility ({ force = false, forceCompatibility = false } = {}) {
this.compilerVersion = await this.getCompilerVersion().catch(e => null)
if (!this.compilerVersion && !force) throw new Error('Compiler do not respond')
if (this.compilerVersion && !semverSatisfies(this.compilerVersion.split('-')[0], COMPILER_GE_VERSION, COMPILER_LT_VERSION)) {
if (!forceCompatibility && this.compilerVersion && !semverSatisfies(this.compilerVersion.split('-')[0], COMPILER_GE_VERSION, COMPILER_LT_VERSION)) {
const version = this.compilerVersion
this.compilerVersion = null
throw new Error(`Unsupported compiler version ${version}. ` +
Expand All @@ -113,9 +113,9 @@ function isInit () {
* @example ContractCompilerAPI({ compilerUrl: 'COMPILER_URL' })
*/
const ContractCompilerAPI = AsyncInit.compose(ContractBase, {
async init ({ compilerUrl = this.compilerUrl }) {
async init ({ compilerUrl = this.compilerUrl, forceCompatibility = false }) {
this.http = Http({ baseUrl: compilerUrl })
await this.checkCompatibility(true)
await this.checkCompatibility({ force: true, forceCompatibility })
},
methods: {
contractEncodeCallDataAPI,
Expand Down
6 changes: 4 additions & 2 deletions es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import Accounts from './accounts'
import MemoryAccount from './account/memory'
import Aens from './ae/aens'
import Contract from './ae/contract'
import GeneralizeAccount from './contract/ga'
// Todo Enable GA
// import GeneralizeAccount from './contract/ga'
import ContractCompilerAPI from './contract/compiler'
import Wallet from './ae/wallet'
import Aepp from './ae/aepp'
Expand All @@ -59,7 +60,8 @@ export {
Channel,
Crypto,
Chain,
GeneralizeAccount,
// Todo Enable GA
// GeneralizeAccount,
HdWallet,
MemoryAccount,
Node,
Expand Down
4 changes: 2 additions & 2 deletions es/node-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import AsyncInit from '../utils/async-init'
* @return {Object} NodePool instance
*/
export const NodePool = AsyncInit.compose({
async init ({ nodes = [], url = this.url, internalUrl = this.internalUrl } = {}) {
async init ({ nodes = [], url = this.url, internalUrl = this.internalUrl, forceCompatibility = false } = {}) {
this.pool = new Map()
this.validateNodes(nodes)

Expand All @@ -32,7 +32,7 @@ export const NodePool = AsyncInit.compose({
// DEPRECATED. TODO Remove deprecated param
// Prevent BREAKING CHANGES. Support for init params `url`, `internalUrl`
if (url) {
this.addNode('default', await Node({ url, internalUrl }), true)
this.addNode('default', await Node({ url, internalUrl, forceCompatibility }), true)
}
},
propertyDescriptors: {
Expand Down
5 changes: 3 additions & 2 deletions es/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ const Node = stampit(AsyncInit, {
const { nodeRevision: revision, genesisKeyBlockHash: genesisHash, networkId, protocols } = await this.api.getStatus()
this.consensusProtocolVersion = await this.getConsensusProtocolVersion(protocols)
if (
!semverSatisfies(this.version.split('-')[0], NODE_GE_VERSION, NODE_LT_VERSION) &&
!(this.version === '5.0.0-rc.1' || semverSatisfies(this.version.split('-')[0], NODE_GE_VERSION, NODE_LT_VERSION)) &&
// Todo implement 'rc' version comparision in semverSatisfies
!forceCompatibility
) {
throw new Error(
Expand All @@ -154,6 +155,6 @@ const Node = stampit(AsyncInit, {
})

const NODE_GE_VERSION = '3.0.1'
const NODE_LT_VERSION = '5.0.0'
const NODE_LT_VERSION = '5.0.0-rc.2'

export default Node
Loading