Skip to content

Commit

Permalink
refactor(chain)!: drop stamps and use plain functions
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Dropped `Chain`, `ChainNode` stamps
Theirs methods added to `Ae` stamps, also they are exported by names in the package root.
Outside of Stamp context, they accepts the `onAccount`, `onNode` options.
  • Loading branch information
davidyuk committed Apr 26, 2022
1 parent cefaa55 commit 3e7f36c
Show file tree
Hide file tree
Showing 11 changed files with 447 additions and 528 deletions.
2 changes: 1 addition & 1 deletion src/ae/aens.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async function claim (name, salt, options) {

const result = await this.send(claimTx, opt)
if (!isAuctionName(name)) {
const nameInter = opt.waitMined ? await this.aensQuery(name, opt) : {}
const nameInter = result.blockHeight ? await this.aensQuery(name, opt) : {}
return Object.assign(result, nameInter)
}
return { ...result, nameFee: opt.nameFee }
Expand Down
3 changes: 1 addition & 2 deletions src/ae/aepp.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import Ae from './'
import Aens from './aens'
import Contract from './contract'
import AeppRpc from '../utils/aepp-wallet-communication/rpc/aepp-rpc'
import Chain from '../chain/node'
import Tx from '../tx/tx'
import Oracle from './oracle'

Expand All @@ -42,4 +41,4 @@ import Oracle from './oracle'
* @param {Object} [options={}] - Initializer object
* @return {Object} Aepp instance
*/
export default Ae.compose(Tx, Oracle, Contract, Aens, Chain, AeppRpc)
export default Ae.compose(Tx, Oracle, Contract, Aens, AeppRpc)
42 changes: 38 additions & 4 deletions src/ae/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@

import stampit from '@stamp/it'
import Tx from '../tx'
import Chain from '../chain'
import AccountBase from '../account/base'
import * as chainMethods from '../chain'
import NodePool from '../node-pool'
import AccountResolver from '../account/resolver'
import { buildTxHash, unpackTx } from '../tx/builder'
import BigNumber from 'bignumber.js'
import { AE_AMOUNT_FORMATS } from '../utils/amount-formatter'
import { ArgumentError } from '../utils/errors'
import { mapObject } from '../utils/other'

/**
* Sign and post a transaction to the chain
Expand Down Expand Up @@ -160,8 +162,40 @@ function destroyInstance () {
* @param {Object} [options={}] - Initializer object
* @return {Object} Ae instance
*/
const Ae = stampit(Tx, AccountBase, Chain, {
methods: { send, spend, transferFunds, payForTransaction, destroyInstance, signUsingGA },
const Ae = stampit(NodePool, Tx, AccountResolver, {
methods: {
send,
spend,
transferFunds,
payForTransaction,
destroyInstance,
signUsingGA,
...mapObject(
chainMethods,
([name, handler]) => [
name,
function (...args) {
const instanceOptions = {
...this.Ae.defaults,
onNode: this.selectedNode.instance,
onAccount: this
}
const lastArg = args[args.length - 1]
if (
lastArg && typeof lastArg === 'object' && lastArg.constructor === Object
) {
Object.assign(lastArg, {
...instanceOptions,
...lastArg,
...lastArg.onAccount && { onAccount: this._resolveAccount(lastArg.onAccount) }
})
}
else args.push(instanceOptions)
return handler(...args)
}
]
)
},
deepProps: { Ae: { defaults: { denomination: AE_AMOUNT_FORMATS.AETTOS } } }
})

Expand Down
3 changes: 1 addition & 2 deletions src/ae/universal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

import Ae from './'
import Chain from '../chain/node'
import Aens from './aens'
import Transaction from '../tx/tx'
import Oracle from './oracle'
Expand All @@ -43,5 +42,5 @@ import Contract from './contract'
* @return {Object} Universal instance
*/
export default Ae.compose(
AccountMultiple, Chain, Transaction, Aens, Contract, Oracle, GeneralizedAccount
AccountMultiple, Transaction, Aens, Contract, Oracle, GeneralizedAccount
)
3 changes: 1 addition & 2 deletions src/ae/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

import Ae from './'
import Chain from '../chain/node'
import Tx from '../tx/tx'
import Contract from './contract'
import GeneralizedAccount from '../contract/ga'
Expand All @@ -47,4 +46,4 @@ import Aens from './aens'
address: keypair.publicKey,
})
*/
export default Ae.compose(WalletRpc, Tx, Contract, Oracle, Aens, GeneralizedAccount, Chain)
export default Ae.compose(WalletRpc, Tx, Contract, Oracle, Aens, GeneralizedAccount)
Loading

0 comments on commit 3e7f36c

Please sign in to comment.