12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 'use strict'
- const debug = require('debug')('joystream:runtime:balances')
- class BalancesApi {
- static async create(base) {
- const ret = new BalancesApi()
- ret.base = base
- await BalancesApi.init()
- return ret
- }
- static async init() {
- debug('Init')
- }
-
- async hasMinimumBalanceOf(accountId, min) {
- const balance = await this.freeBalance(accountId)
- if (typeof min === 'number') {
- return balance.cmpn(min) >= 0
- }
- return balance.cmp(min) >= 0
- }
-
- async freeBalance(accountId) {
- const decoded = this.base.identities.keyring.decodeAddress(accountId, true)
- return this.base.api.query.balances.freeBalance(decoded)
- }
-
- baseTransactionFee() {
- return this.base.api.consts.transactionPayment.transactionBaseFee
- }
-
- async transfer(from, to, amount) {
- const decode = require('@polkadot/keyring').decodeAddress
- const toDecoded = decode(to, true)
- const tx = this.base.api.tx.balances.transfer(toDecoded, amount)
- return this.base.signAndSend(from, tx)
- }
- }
- module.exports = {
- BalancesApi,
- }
|