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

feat(GA): Disable GA #631

Merged
merged 9 commits into from
Aug 28, 2019
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
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
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
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 = '6.0.0'
const NODE_LT_VERSION = '5.0.0-rc.2'

export default Node
7 changes: 5 additions & 2 deletions es/tx/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const Tx = stampit({
'spendTx', 'namePreclaimTx', 'nameClaimTx', 'nameTransferTx',
'nameUpdateTx', 'nameRevokeTx', 'contractCreateTx', 'contractCallTx',
'oracleRegisterTx', 'oracleExtendTx', 'oraclePostQueryTx', 'oracleRespondTx', 'getAccountNonce',
'channelCloseSoloTx', 'channelSlashTx', 'channelSettleTx', 'channelSnapshotSoloTx', 'gaAttachTx', 'getVmVersion', 'prepareTxParams'
'channelCloseSoloTx', 'channelSlashTx', 'channelSettleTx', 'channelSnapshotSoloTx', 'getVmVersion', 'prepareTxParams'
// Todo Enable GA
// 'gaAttachTx',
]
}
}
Expand All @@ -71,7 +73,8 @@ const Tx = stampit({
channelSlashTx: required,
channelSettleTx: required,
channelSnapshotSoloTx: required,
gaAttachTx: required,
// Todo Enable GA
// gaAttachTx: required,
getVmVersion: required,
prepareTxParams: required
}
Expand Down
4 changes: 3 additions & 1 deletion es/tx/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ async function channelSnapshotSoloTx ({ channelId, fromId, payload }) {
return tx
}

// eslint-disable-next-line no-unused-vars
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))
Expand Down Expand Up @@ -473,7 +474,8 @@ const Transaction = ChainNode.compose(Tx, {
channelSlashTx,
channelSettleTx,
channelSnapshotSoloTx,
gaAttachTx,
// Todo Enable GA
// gaAttachTx,
getAccountNonce,
getVmVersion
}
Expand Down
6 changes: 3 additions & 3 deletions es/utils/semver-satisfies.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function (version, geVersion, ltVersion) {
const versionComponents = version.split('.')
const geComponents = geVersion.split('.')
const ltComponents = ltVersion.split('.')
const versionComponents = version.split('-')[0].split('.')
const geComponents = geVersion.split('-')[0].split('.')
const ltComponents = ltVersion.split('-')[0].split('.')
const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1
const toNumber = components => components.reverse()
.reduce((acc, n, idx) => acc + n * Math.pow(base, idx), 0)
Expand Down
3 changes: 2 additions & 1 deletion test/integration/ga.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const authContract = `contract BlindAuth =
None => abort("Not in Auth context")
Some(tx_hash) => true
`
describe('Generalize Account', function () {
// Todo Enable GA
describe.skip('Generalize Account', function () {
configure(this)

let client
Expand Down
2 changes: 2 additions & 0 deletions test/unit/semver-satisfies.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ describe('semverSatisfies', () => {
expect(semverSatisfies('2.4.0', '1.4.0', '3.0.0')).to.equal(true)
expect(semverSatisfies('2.4.0', '2.5.0', '3.0.0')).to.equal(false)
expect(semverSatisfies('1.9.0', '2.0.0', '3.0.0')).to.equal(false)
expect(semverSatisfies('1.9.0', '2.0.0', '3.0.0')).to.equal(false)
expect(semverSatisfies('5.0.0', '3.0.0', '5.0.0')).to.equal(false)
})
})