Skip to content

Commit

Permalink
refactor(chain)!: remove deprecated methods
Browse files Browse the repository at this point in the history
BREAKING CHANGE: removed `sdk.balance` method
Use `sdk.getBalance` instead.

BREAKING CHANGE: removed `sdk.tx` method
Use `sdk.api.getTransactionByHash/getTransactionInfoByHash` instead.

BREAKING CHANGE: removed `sdk.getTxInfo` method
Use `sdk.api.getTransactionInfoByHash` instead.
  • Loading branch information
davidyuk committed Apr 26, 2022
1 parent 002035b commit cefaa55
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 87 deletions.
4 changes: 2 additions & 2 deletions docs/guides/connect-aepp-to-wallet.md
Expand Up @@ -44,7 +44,7 @@ async created () {
},
onAddressChange: async () => {
this.address = await this.aeSdk.address()
this.balance = await this.aeSdk.balance(this.address)
this.balance = await this.aeSdk.getBalance(this.address)
},
onDisconnect: () => {
// you may want to reset state here
Expand Down Expand Up @@ -87,7 +87,7 @@ async connect(wallet) {
await this.aeSdk.connectToWallet(await wallet.getConnection())
this.connectedAccounts = await this.aeSdk.subscribeAddress('subscribe', 'connected')
this.address = await this.aeSdk.address()
this.balance = await this.aeSdk.balance(this.address).catch(() => '0')
this.balance = await this.aeSdk.getBalance(this.address).catch(() => '0')
this.nodeInfo = await this.aeSdk.getNodeInfo()
}
```
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/aepp/src/Basic.vue
Expand Up @@ -81,7 +81,7 @@ export default {
([aeSdk, address]) => {
if (!aeSdk) return
this.compilerVersion = aeSdk.compilerVersion
this.balancePromise = aeSdk.balance(address)
this.balancePromise = aeSdk.getBalance(address)
this.heightPromise = aeSdk.height()
this.nodeInfoPromise = aeSdk.getNodeInfo()
},
Expand Down
2 changes: 1 addition & 1 deletion src/ae/index.js
Expand Up @@ -100,7 +100,7 @@ async function transferFunds (fraction, recipientIdOrName, options) {
const opt = { ...this.Ae.defaults, ...options }
const recipientId = await this.resolveName(recipientIdOrName, 'account_pubkey', opt)
const senderId = await this.address(opt)
const balance = new BigNumber(await this.balance(senderId))
const balance = new BigNumber(await this.getBalance(senderId))
const desiredAmount = balance.times(fraction).integerValue(BigNumber.ROUND_HALF_UP)
const { tx: { fee } } = unpackTx(
await this.spendTx({ ...opt, senderId, recipientId, amount: desiredAmount })
Expand Down
29 changes: 1 addition & 28 deletions src/chain/index.js
Expand Up @@ -64,10 +64,7 @@ const Chain = stampit({
height: required,
awaitHeight: required,
poll: required,
balance: required,
getBalance: required,
tx: required,
getTxInfo: required,
txDryRun: required,
getAccount: required
}
Expand Down Expand Up @@ -124,7 +121,7 @@ const Chain = stampit({

/**
* Request the balance of specified account
* @function balance
* @function getBalance
* @instance
* @abstract
* @category async
Expand All @@ -138,30 +135,6 @@ const Chain = stampit({
* @return {Object} The transaction as it was mined
*/

/**
* Obtain a transaction based on its hash
* @function tx
* @instance
* @abstract
* @category async
* @rtype (hash: String, info = false) => tx: Object
* @param {String} hash - Transaction hash
* @param {Boolean} info - Retrieve additional transaction date. Works only for (ContractCreate and
* ContractCall transaction's)
* @return {Object} Transaction
*/

/**
* Obtain a transaction info based on its hash
* @function getTxInfo
* @instance
* @abstract
* @category async
* @rtype (hash: String) => tx: Object
* @param {String} hash - Transaction hash
* @return {Object} Transaction
*/

/**
* Obtain current generation
* @function getCurrentGeneration
Expand Down
34 changes: 0 additions & 34 deletions src/chain/node.js
Expand Up @@ -99,35 +99,12 @@ async function getAccount (address, { height, hash } = {}) {
return this.api.getAccountByPubkey(address)
}

/**
* @function
* @deprecated
*/
async function balance (address, { height, hash, format = AE_AMOUNT_FORMATS.AETTOS } = {}) {
const { balance } = await this.getAccount(address, { hash, height })

return formatAmount(balance, { targetDenomination: format }).toString()
}

async function getBalance (address, { height, hash, format = AE_AMOUNT_FORMATS.AETTOS } = {}) {
const { balance } = await this.getAccount(address, { hash, height }).catch(() => ({ balance: 0 }))

return formatAmount(balance, { targetDenomination: format }).toString()
}

/**
* @deprecated use `sdk.api.getTransactionByHash/getTransactionInfoByHash` instead
*/
async function tx (hash, info = true) {
const tx = await this.api.getTransactionByHash(hash)
if (['ContractCreateTx', 'ContractCallTx', 'ChannelForceProgressTx'].includes(tx.tx.type) && info && tx.blockHeight !== -1) {
try {
return { ...tx, ...await this.getTxInfo(hash) }
} catch (e) {}
}
return tx
}

async function height () {
return (await this.api.getCurrentKeyBlockHeight()).height
}
Expand Down Expand Up @@ -155,14 +132,6 @@ async function poll (th, { blocks = 10, interval = this._getPollInterval('microb
throw new TxTimedOutError(blocks, th)
}

/**
* @deprecated use `sdk.api.getTransactionInfoByHash` instead
*/
async function getTxInfo (hash) {
const result = await this.api.getTransactionInfoByHash(hash)
return result.callInfo || result
}

async function getCurrentGeneration () {
return this.api.getCurrentGeneration()
}
Expand Down Expand Up @@ -289,14 +258,11 @@ async function resolveName (nameOrId, key, { verify, resolveByNode } = {}) {
const ChainNode = Chain.compose(NodePool, {
methods: {
sendTransaction,
balance,
getBalance,
getAccount,
tx,
height,
awaitHeight,
poll,
getTxInfo,
getCurrentGeneration,
getGeneration,
getMicroBlockHeader,
Expand Down
14 changes: 5 additions & 9 deletions test/integration/accounts.js
Expand Up @@ -49,10 +49,6 @@ describe('Accounts', function () {
await wallet.addAccount(MemoryAccount({ keypair: generateKeyPair() }), { select: true })
})

it('determining the balance using deprecated `balance` method', async () => {
return wallet.balance(await wallet.address()).should.be.rejectedWith(Error)
})

it('determining the balance', async () => {
return wallet.getBalance(await wallet.address()).should.eventually.be.equal('0')
})
Expand All @@ -66,14 +62,14 @@ describe('Accounts', function () {
})

it('determines the balance using `balance`', async () => {
return aeSdk.balance(await aeSdk.address()).should.eventually.be.a('string')
return aeSdk.getBalance(await aeSdk.address()).should.eventually.be.a('string')
})

describe('transferFunds', async () => {
const spend = async fraction => {
const balanceBefore = new BigNumber(await aeSdk.balance(await aeSdk.address()))
const balanceBefore = new BigNumber(await aeSdk.getBalance(await aeSdk.address()))
const { tx } = await aeSdk.transferFunds(fraction, receiver)
const balanceAfter = new BigNumber(await aeSdk.balance(await aeSdk.address()))
const balanceAfter = new BigNumber(await aeSdk.getBalance(await aeSdk.address()))
return {
balanceBefore,
balanceAfter,
Expand Down Expand Up @@ -105,7 +101,7 @@ describe('Accounts', function () {

it('accepts onAccount option', async () => {
await aeSdk.transferFunds(1, await aeSdk.address(), { onAccount: receiverKey })
new BigNumber(await aeSdk.balance(receiver)).isZero().should.be.equal(true)
new BigNumber(await aeSdk.getBalance(receiver)).isZero().should.be.equal(true)
})
})

Expand All @@ -131,7 +127,7 @@ describe('Accounts', function () {
const receiverWallet = generateKeyPair()
const ret = await genesis.spend(bigAmount, receiverWallet.publicKey)

const balanceAfter = await aeSdk.balance(receiverWallet.publicKey)
const balanceAfter = await aeSdk.getBalance(receiverWallet.publicKey)
balanceAfter.should.be.equal(bigAmount)
ret.should.have.property('tx')
ret.tx.should.include({
Expand Down
16 changes: 8 additions & 8 deletions test/integration/channel.js
Expand Up @@ -748,8 +748,8 @@ describe('Channel', function () {
accounts: [initiatorAddr, responderAddr]
})
const balances = await initiatorCh.balances([initiatorAddr, responderAddr])
const initiatorBalanceBeforeClose = await aeSdkInitiatior.balance(initiatorAddr)
const responderBalanceBeforeClose = await aeSdkResponder.balance(responderAddr)
const initiatorBalanceBeforeClose = await aeSdkInitiatior.getBalance(initiatorAddr)
const responderBalanceBeforeClose = await aeSdkResponder.getBalance(responderAddr)
const closeSoloTx = await aeSdkInitiatior.channelCloseSoloTx({
channelId: await initiatorCh.id(),
fromId: initiatorAddr,
Expand All @@ -770,8 +770,8 @@ describe('Channel', function () {
const settleTxFee = unpackTx(settleTx).tx.fee
await aeSdkInitiatior.sendTransaction(
await aeSdkInitiatior.signTransaction(settleTx), { waitMined: true })
const initiatorBalanceAfterClose = await aeSdkInitiatior.balance(initiatorAddr)
const responderBalanceAfterClose = await aeSdkResponder.balance(responderAddr)
const initiatorBalanceAfterClose = await aeSdkInitiatior.getBalance(initiatorAddr)
const responderBalanceAfterClose = await aeSdkResponder.getBalance(responderAddr)
new BigNumber(initiatorBalanceAfterClose)
.minus(initiatorBalanceBeforeClose)
.plus(closeSoloTxFee)
Expand Down Expand Up @@ -804,8 +804,8 @@ describe('Channel', function () {
port: 3004
})
await Promise.all([waitForChannel(initiatorCh), waitForChannel(responderCh)])
const initiatorBalanceBeforeClose = await aeSdkInitiatior.balance(initiatorAddr)
const responderBalanceBeforeClose = await aeSdkResponder.balance(responderAddr)
const initiatorBalanceBeforeClose = await aeSdkInitiatior.getBalance(initiatorAddr)
const responderBalanceBeforeClose = await aeSdkResponder.getBalance(responderAddr)
const oldUpdate = await initiatorCh.update(
initiatorAddr, responderAddr, 100, (tx) => aeSdkInitiatior.signTransaction(tx)
)
Expand Down Expand Up @@ -847,8 +847,8 @@ describe('Channel', function () {
const settleTxFee = unpackTx(settleTx).tx.fee
await aeSdkResponder.sendTransaction(
await aeSdkResponder.signTransaction(settleTx), { waitMined: true })
const initiatorBalanceAfterClose = await aeSdkInitiatior.balance(initiatorAddr)
const responderBalanceAfterClose = await aeSdkResponder.balance(responderAddr)
const initiatorBalanceAfterClose = await aeSdkInitiatior.getBalance(initiatorAddr)
const responderBalanceAfterClose = await aeSdkResponder.getBalance(responderAddr)
new BigNumber(initiatorBalanceAfterClose)
.minus(initiatorBalanceBeforeClose)
.plus(closeSoloTxFee)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/contract-aci.js
Expand Up @@ -304,9 +304,9 @@ describe('Contract instance', function () {
})

it('pays to payable function', async () => {
const contractBalance = await aeSdk.balance(testContract.deployInfo.address)
const contractBalance = await aeSdk.getBalance(testContract.deployInfo.address)
await testContract.methods.stringFn.send('test', { amount: 100 })
const balanceAfter = await aeSdk.balance(testContract.deployInfo.address)
const balanceAfter = await aeSdk.getBalance(testContract.deployInfo.address)
balanceAfter.should.be.equal(`${+contractBalance + 100}`)
})

Expand Down
2 changes: 1 addition & 1 deletion test/integration/ga.js
Expand Up @@ -72,7 +72,7 @@ describe('Generalized Account', function () {
const callData = authContract.calldata.encode('BlindAuth', 'authorize', [r()])
await aeSdk.spend(10000, publicKey, { authData: { callData } })
await aeSdk.spend(10000, publicKey, { authData: { source: authContractSource, args: [r()] } })
const balanceAfter = await aeSdk.balance(publicKey)
const balanceAfter = await aeSdk.getBalance(publicKey)
balanceAfter.should.be.equal('20000')
})

Expand Down
2 changes: 1 addition & 1 deletion test/integration/paying-for.js
Expand Up @@ -38,7 +38,7 @@ describe('Paying for transaction of another account', function () {
amount: 1e4
})
const signedSpendTx = await aeSdk.signTransaction(spendTx, { onAccount: sender, innerTx: true })
const payerBalanceBefore = await aeSdk.balance(await aeSdk.address())
const payerBalanceBefore = await aeSdk.getBalance(await aeSdk.address())
const {
fee: outerFee, tx: { tx: { fee: innerFee } }
} = (await aeSdk.payForTransaction(signedSpendTx)).tx
Expand Down

0 comments on commit cefaa55

Please sign in to comment.