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

Add utxosToAccount rpc #215

Merged
merged 20 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions packages/jellyfish-api-core/__tests__/category/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,44 @@ describe('masternode', () => {
})
})
})

describe('utxosToAccount', () => {
let address1: string
let address2: string

beforeAll(async () => {
address1 = await container.call('getnewaddress')
address2 = await container.call('getnewaddress')
})

it('should utxosToAccount', async () => {
const payload: any = {}
payload[address1] = '5@DFI'
payload[address2] = '5@DFI'
jingyi2811 marked this conversation as resolved.
Show resolved Hide resolved

const data = await client.account.utxosToAccount(payload)

expect(typeof data).toBe('string')
expect(data.length).toBe(64)
})

it('should utxosToAccount with utxos', async () => {
const payload: any = {}
payload[address1] = '5@DFI'
payload[address2] = '5@DFI'
jingyi2811 marked this conversation as resolved.
Show resolved Hide resolved

const utxos = await container.call('listunspent')
const inputs = utxos.map((utxo: { txid: string, vout: number }) => {
return {
txid: utxo.txid,
vout: utxo.vout
}
})

const data = await client.account.utxosToAccount(payload, inputs)

expect(typeof data).toBe('string')
expect(data.length).toBe(64)
})
})
})
19 changes: 19 additions & 0 deletions packages/jellyfish-api-core/src/category/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ export class Account {
): Promise<AccountHistory[]> {
return await this.client.call('listaccounthistory', [owner, options], 'number')
}

/**
* 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]
jingyi2811 marked this conversation as resolved.
Show resolved Hide resolved
* @param {UtxosToAccountUTXO[]} [options=[]]
* @param {string} [options.txid]
* @param {number} [options.vout]
* @return {Promise<string>}
*/
async utxosToAccount (payload: any, options: UtxosToAccountUTXO[] = []): Promise<string> {
jingyi2811 marked this conversation as resolved.
Show resolved Hide resolved
return await this.client.call('utxostoaccount', [payload, options], 'number')
}
}

export interface AccountPagination {
Expand Down Expand Up @@ -277,3 +291,8 @@ export interface AccountHistoryOptions {
txtype?: string
limit?: number
}

export interface UtxosToAccountUTXO {
txid: string
vout: number
}
16 changes: 16 additions & 0 deletions website/docs/jellyfish/api/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,19 @@ interface AccountHistoryOptions {
limit?: number
}
```

## utxosToAccount

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.

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

interface UtxosToAccountUTXO {
txid: string
vout: number
}
```