Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyi2811 committed May 17, 2021
1 parent 8211bea commit f124f6d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../container_adapter_client'
import waitForExpect from 'wait-for-expect'
import BigNumber from 'bignumber.js'
import { UtxosToAccountPayload } from '../../src/category/account'

describe('masternode', () => {
const container = new MasterNodeRegTestContainer()
Expand Down Expand Up @@ -490,7 +491,8 @@ describe('masternode', () => {
})

it('should utxosToAccount', async () => {
const payload: any = {}
const payload: UtxosToAccountPayload = {}
// NOTE(jingyi2811): Only support sending utxos to DFI account.
payload[address1] = '5@DFI'
payload[address2] = '5@DFI'

Expand All @@ -501,7 +503,8 @@ describe('masternode', () => {
})

it('should utxosToAccount with utxos', async () => {
const payload: any = {}
const payload: UtxosToAccountPayload = {}
// NOTE(jingyi2811): Only support sending utxos to DFI account.
payload[address1] = '5@DFI'
payload[address2] = '5@DFI'

Expand Down
16 changes: 10 additions & 6 deletions packages/jellyfish-api-core/src/category/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,14 @@ export class Account {
* Creates (and submits to local node and network) a transfer transaction from the wallet UTXOs to specfied account.
* The second optional argument (may be empty array) is an array of specific UTXOs to spend.
*
* @param {any} [payload]
* @param {UtxosToAccountUTXO[]} [options=[]]
* @param {string} [options.txid]
* @param {number} [options.vout]
* @param {UtxosToAccountPayload} [payload]
* @param {UtxosToAccountUTXO[]} [utxos=[]]
* @param {string} [utxos.txid]
* @param {number} [utxos.vout]
* @return {Promise<string>}
*/
async utxosToAccount (payload: any, options: UtxosToAccountUTXO[] = []): Promise<string> {
return await this.client.call('utxostoaccount', [payload, options], 'number')
async utxosToAccount (payload: UtxosToAccountPayload, utxos: UtxosToAccountUTXO[] = []): Promise<string> {
return await this.client.call('utxostoaccount', [payload, utxos], 'number')
}
}

Expand Down Expand Up @@ -292,6 +292,10 @@ export interface AccountHistoryOptions {
limit?: number
}

export interface UtxosToAccountPayload {
[key: string]: string
}

export interface UtxosToAccountUTXO {
txid: string
vout: number
Expand Down
6 changes: 5 additions & 1 deletion website/docs/jellyfish/api/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ The second optional argument (may be empty array) is an array of specific UTXOs

```ts title="client.account.utxosToAccount()"
interface account {
utxosToAccount (payload: any, options: UtxosToAccountUTXO[] = []): Promise<string>
utxosToAccount (payload: UtxosToAccountPayload, utxos: UtxosToAccountUTXO[] = []): Promise<string>
}

interface UtxosToAccountPayload {
[key: string]: string;
}

interface UtxosToAccountUTXO {
Expand Down

0 comments on commit f124f6d

Please sign in to comment.