Skip to content

Commit 6c39479

Browse files
authored
Merge pull request #2536 from GrassRootsCrypto/Issue-2535
Issue 2535 - Can't get UTXO Balance
2 parents 14ad7a1 + 07ab61c commit 6c39479

File tree

13 files changed

+240
-139
lines changed

13 files changed

+240
-139
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@ yarn-error.log*
3131
# don't share .env, but .env.sample
3232
.env
3333

34+
# don't need to share yarn.lock
35+
yarn.lock
36+
3437
dev-app-update.yml
3538
/.idea/

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 1.19.1 (2023-04-XX)
2+
3+
# Internal
4+
5+
-Updates/refactor to support latest xchain updates for UTXO support. Keystore clients and ledger code updated.
6+
17
# 1.19.0 (2023-01-xx)
28

39
## Add

package.json

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "asgardex",
33
"productName": "ASGARDEX",
4-
"version": "1.18.6",
4+
"version": "1.19.1-alpha",
55
"description": "WALLET AND EXCHANGE CLIENT FOR THORCHAIN",
66
"main": "index.js",
77
"scripts": {
@@ -88,16 +88,17 @@
8888
"@thorchain/ledger-thorchain": "^0.1.0-alpha.2",
8989
"@types/electron-devtools-installer": "^2.2.2",
9090
"@xchainjs/xchain-binance": "^5.6.7",
91-
"@xchainjs/xchain-bitcoin": "^0.20.8",
92-
"@xchainjs/xchain-bitcoincash": "^0.15.7",
93-
"@xchainjs/xchain-client": "^0.13.5",
94-
"@xchainjs/xchain-cosmos": "0.20.7",
95-
"@xchainjs/xchain-crypto": "^0.2.6",
96-
"@xchainjs/xchain-doge": "^0.5.7",
91+
"@xchainjs/xchain-bitcoin": "^0.21.1",
92+
"@xchainjs/xchain-bitcoincash": "^0.15.9",
93+
"@xchainjs/xchain-client": "^0.13.6",
94+
"@xchainjs/xchain-cosmos": "0.20.8",
95+
"@xchainjs/xchain-crypto": "^0.2.7",
96+
"@xchainjs/xchain-doge": "^0.5.10",
9797
"@xchainjs/xchain-ethereum": "^0.27.7",
98-
"@xchainjs/xchain-litecoin": "^0.10.9",
99-
"@xchainjs/xchain-thorchain": "^0.27.8",
98+
"@xchainjs/xchain-litecoin": "^0.11.1",
99+
"@xchainjs/xchain-thorchain": "^0.27.9",
100100
"@xchainjs/xchain-util": "^0.12.0",
101+
"@xchainjs/xchain-utxo-providers": "^0.1.1",
101102
"antd": "^4.20.7",
102103
"axios": "^0.25.0",
103104
"bchaddrjs": "^0.5.2",

src/main/api/ledger/bitcoin/transaction.ts

+21-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import AppBTC from '@ledgerhq/hw-app-btc'
22
import { Transaction } from '@ledgerhq/hw-app-btc/lib/types'
33
import Transport from '@ledgerhq/hw-transport'
4-
import { broadcastTx, buildTx, LOWER_FEE_BOUND, UPPER_FEE_BOUND } from '@xchainjs/xchain-bitcoin'
4+
import {
5+
AssetBTC,
6+
BTCChain,
7+
Client,
8+
defaultBTCParams,
9+
LOWER_FEE_BOUND,
10+
UPPER_FEE_BOUND
11+
} from '@xchainjs/xchain-bitcoin'
512
import { checkFeeBounds, FeeRate, TxHash } from '@xchainjs/xchain-client'
613
import { Address, BaseAmount } from '@xchainjs/xchain-util'
14+
import { HaskoinProvider, HaskoinNetwork } from '@xchainjs/xchain-utxo-providers'
715
import * as Bitcoin from 'bitcoinjs-lib'
816
import * as E from 'fp-ts/lib/Either'
917

1018
import { getHaskoinBTCApiUrl } from '../../../../shared/api/haskoin'
11-
import { getSochainUrl } from '../../../../shared/api/sochain'
1219
import { LedgerError, LedgerErrorId, Network } from '../../../../shared/api/types'
1320
import { toClientNetwork } from '../../../../shared/utils/client'
1421
import { isError } from '../../../../shared/utils/guard'
@@ -63,19 +70,19 @@ export const send = async ({
6370
*/
6471
const spendPendingUTXO = !memo
6572

66-
const haskoinUrl = getHaskoinBTCApiUrl()[network]
73+
const btcInitParams = {
74+
...defaultBTCParams,
75+
network: clientNetwork
76+
}
77+
const btcClient = new Client(btcInitParams)
6778

68-
const { psbt, utxos } = await buildTx({
79+
const { psbt, utxos } = await btcClient.buildTx({
6980
amount,
7081
recipient,
7182
memo,
7283
feeRate,
7384
sender,
74-
network: clientNetwork,
75-
sochainUrl: getSochainUrl(),
76-
haskoinUrl,
77-
spendPendingUTXO,
78-
withTxHex: true
85+
spendPendingUTXO
7986
})
8087

8188
const inputs: Array<[Transaction, number, string | null, number | null]> = utxos.map(({ txHex, hash, index }) => {
@@ -102,7 +109,11 @@ export const send = async ({
102109
useTrustedInputForSegwit: true,
103110
additionals: ['bech32']
104111
})
105-
const txHash = await broadcastTx({ txHex, haskoinUrl })
112+
113+
const haskoinUrl = getHaskoinBTCApiUrl()[network] //https://haskoin.ninerealms.com
114+
const haskoinProvider = new HaskoinProvider(haskoinUrl, BTCChain, AssetBTC, 8, HaskoinNetwork.BTC)
115+
116+
const txHash = await haskoinProvider.broadcastTx(txHex)
106117

107118
if (!txHash) {
108119
return E.left({

src/main/api/ledger/bitcoincash/transaction.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import AppBTC from '@ledgerhq/hw-app-btc'
22
import { Transaction } from '@ledgerhq/hw-app-btc/lib/types'
33
import Transport from '@ledgerhq/hw-transport'
4-
import { broadcastTx, buildTx, LOWER_FEE_BOUND, UPPER_FEE_BOUND } from '@xchainjs/xchain-bitcoincash'
4+
import {
5+
AssetBCH,
6+
BCHChain,
7+
Client,
8+
defaultBCHParams,
9+
LOWER_FEE_BOUND,
10+
UPPER_FEE_BOUND
11+
} from '@xchainjs/xchain-bitcoincash'
512
import { checkFeeBounds, FeeRate, TxHash } from '@xchainjs/xchain-client'
613
import { Address, BaseAmount } from '@xchainjs/xchain-util'
14+
import { HaskoinProvider, HaskoinNetwork } from '@xchainjs/xchain-utxo-providers'
715
import * as Bitcoin from 'bitcoinjs-lib'
816
import * as E from 'fp-ts/lib/Either'
917

@@ -55,15 +63,21 @@ export const send = async ({
5563
const derivePath = getDerivationPath(walletIndex, clientNetwork)
5664

5765
const haskoinUrl = getHaskoinBCHApiUrl()[network]
66+
const haskoinProvider = new HaskoinProvider(haskoinUrl, BCHChain, AssetBCH, 8, HaskoinNetwork.BCH)
5867

59-
const { builder, inputs: txInputs } = await buildTx({
68+
const bchInitParams = {
69+
...defaultBCHParams,
70+
network: clientNetwork
71+
}
72+
73+
const bchClient = new Client(bchInitParams)
74+
75+
const { builder, inputs: txInputs } = await bchClient.buildTx({
6076
amount,
6177
recipient,
6278
memo,
6379
feeRate,
64-
sender,
65-
network: clientNetwork,
66-
haskoinUrl
80+
sender
6781
})
6882

6983
const inputs: Array<[Transaction, number, string | null, number | null]> = txInputs.map(
@@ -95,7 +109,7 @@ export const send = async ({
95109
sigHashType: 0x41 // If not set, Ledger will throw LEDGER DEVICE: INVALID DATA RECEIVED (0X6A80)
96110
})
97111

98-
const txHash = await broadcastTx({ txHex, haskoinUrl })
112+
const txHash = await haskoinProvider.broadcastTx(txHex)
99113

100114
if (!txHash) {
101115
return E.left({

src/main/api/ledger/doge/transaction.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ import AppBTC from '@ledgerhq/hw-app-btc'
22
import { Transaction } from '@ledgerhq/hw-app-btc/lib/types'
33
import Transport from '@ledgerhq/hw-transport'
44
import { checkFeeBounds, FeeRate, TxHash } from '@xchainjs/xchain-client'
5-
import { broadcastTx, buildTx, getSendTxUrl, LOWER_FEE_BOUND, UPPER_FEE_BOUND } from '@xchainjs/xchain-doge'
5+
import {
6+
AssetDOGE,
7+
Client,
8+
DOGEChain,
9+
getSendTxUrl,
10+
LOWER_FEE_BOUND,
11+
UPPER_FEE_BOUND,
12+
defaultDogeParams
13+
} from '@xchainjs/xchain-doge'
614
import { Address, BaseAmount } from '@xchainjs/xchain-util'
15+
import { BlockcypherProvider, BlockcypherNetwork } from '@xchainjs/xchain-utxo-providers'
716
import * as E from 'fp-ts/lib/Either'
817

918
import { getBlockcypherUrl } from '../../../../shared/api/blockcypher'
10-
import { getSochainUrl } from '../../../../shared/api/sochain'
1119
import { LedgerError, LedgerErrorId, Network } from '../../../../shared/api/types'
1220
import { toClientNetwork } from '../../../../shared/utils/client'
1321
import { isError } from '../../../../shared/utils/guard'
@@ -54,15 +62,19 @@ export const send = async ({
5462
const clientNetwork = toClientNetwork(network)
5563
const derivePath = getDerivationPath(walletIndex, clientNetwork)
5664

57-
const { psbt, utxos } = await buildTx({
65+
const dogeInitParams = {
66+
...defaultDogeParams,
67+
network: clientNetwork
68+
}
69+
70+
const dogeClient = new Client(dogeInitParams)
71+
72+
const { psbt, utxos } = await dogeClient.buildTx({
5873
amount,
5974
recipient,
6075
memo,
6176
feeRate,
62-
sender,
63-
network: clientNetwork,
64-
sochainUrl: getSochainUrl(),
65-
withTxHex: true
77+
sender
6678
})
6779

6880
const inputs: Array<[Transaction, number, string | null, number | null]> = utxos.map(({ txHex, hash, index }) => {
@@ -90,8 +102,9 @@ export const send = async ({
90102

91103
// Note: DOGE Ledger is not supported on `testnet` - all txs will be broadcasted to Blockcypher
92104
const nodeUrl = getSendTxUrl({ network: clientNetwork, blockcypherUrl: getBlockcypherUrl() })
105+
const blockcypherProvider = new BlockcypherProvider(nodeUrl, DOGEChain, AssetDOGE, 8, BlockcypherNetwork.DOGE)
93106

94-
const txHash = await broadcastTx({ network: clientNetwork, txHex, nodeUrl })
107+
const txHash = await blockcypherProvider.broadcastTx(txHex)
95108

96109
if (!txHash) {
97110
return E.left({

src/main/api/ledger/litecoin/transaction.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@ import AppBTC from '@ledgerhq/hw-app-btc'
22
import { Transaction } from '@ledgerhq/hw-app-btc/lib/types'
33
import Transport from '@ledgerhq/hw-transport'
44
import { checkFeeBounds, FeeRate, TxHash } from '@xchainjs/xchain-client'
5-
import { broadcastTx, buildTx, LOWER_FEE_BOUND, UPPER_FEE_BOUND } from '@xchainjs/xchain-litecoin'
5+
import { broadcastTx, Client, defaultLTCParams, LOWER_FEE_BOUND, UPPER_FEE_BOUND } from '@xchainjs/xchain-litecoin'
66
import { Address, BaseAmount } from '@xchainjs/xchain-util'
77
import * as Bitcoin from 'bitcoinjs-lib'
88
import * as E from 'fp-ts/lib/Either'
99

1010
import { getLTCNodeAuth, getLTCNodeUrl } from '../../../../shared/api/litecoin'
11-
import { getSochainUrl } from '../../../../shared/api/sochain'
1211
import { LedgerError, LedgerErrorId, Network } from '../../../../shared/api/types'
1312
import { toClientNetwork } from '../../../../shared/utils/client'
1413
import { isError } from '../../../../shared/utils/guard'
@@ -55,15 +54,18 @@ export const send = async ({
5554
const clientNetwork = toClientNetwork(network)
5655
const derivePath = getDerivationPath(walletIndex, clientNetwork)
5756

58-
const { psbt, utxos } = await buildTx({
57+
const ltcInitParams = {
58+
...defaultLTCParams,
59+
network: clientNetwork
60+
}
61+
const ltcClient = new Client(ltcInitParams)
62+
63+
const { psbt, utxos } = await ltcClient.buildTx({
5964
amount,
6065
recipient,
6166
memo,
6267
feeRate,
63-
sender,
64-
network: clientNetwork,
65-
sochainUrl: getSochainUrl(),
66-
withTxHex: true
68+
sender
6769
})
6870

6971
const inputs: Array<[Transaction, number, string | null, number | null]> = utxos.map(({ txHex, hash, index }) => {

src/renderer/helpers/clientHelper.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Client as BnbClient } from '@xchainjs/xchain-binance'
2-
import { Client as BtcClient } from '@xchainjs/xchain-bitcoin'
2+
import { Client as BtcClient, defaultBTCParams } from '@xchainjs/xchain-bitcoin'
33

44
import { MOCK_PHRASE } from '../../shared/mock/wallet'
55
import { isBnbClient } from './clientHelper'
@@ -11,7 +11,11 @@ describe('helpers/clientHelper', () => {
1111
expect(isBnbClient(client)).toBeTruthy()
1212
})
1313
it('returns false for BTC client', () => {
14-
const client = new BtcClient({ phrase: MOCK_PHRASE })
14+
const btcInitParams = {
15+
...defaultBTCParams,
16+
phrase: MOCK_PHRASE
17+
}
18+
const client = new BtcClient(btcInitParams)
1519
expect(isBnbClient(client)).toBeFalsy()
1620
})
1721
})

src/renderer/services/bitcoin/common.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as RD from '@devexperts/remote-data-ts'
2-
import { BTCChain, Client as BitcoinClient } from '@xchainjs/xchain-bitcoin'
2+
import { AssetBTC, BTCChain, BTC_DECIMAL, Client as BitcoinClient, defaultBTCParams } from '@xchainjs/xchain-bitcoin'
3+
import { HaskoinNetwork, HaskoinProvider } from '@xchainjs/xchain-utxo-providers'
34
import * as FP from 'fp-ts/lib/function'
45
import * as O from 'fp-ts/lib/Option'
56
import * as Rx from 'rxjs'
67
import { Observable } from 'rxjs'
78
import * as RxOp from 'rxjs/operators'
89

910
import { getHaskoinBTCApiUrl } from '../../../shared/api/haskoin'
10-
import { getSochainUrl } from '../../../shared/api/sochain'
1111
import { isError } from '../../../shared/utils/guard'
1212
import { clientNetwork$ } from '../app/service'
1313
import * as C from '../clients'
@@ -31,12 +31,19 @@ const clientState$: ClientState$ = FP.pipe(
3131
getPhrase(keystore),
3232
O.map<string, ClientState>((phrase) => {
3333
try {
34-
const client = new BitcoinClient({
35-
network,
36-
phrase,
37-
haskoinUrl: getHaskoinBTCApiUrl(),
38-
sochainUrl: getSochainUrl()
39-
})
34+
const btcInitParams = {
35+
...defaultBTCParams,
36+
phrase: phrase,
37+
network: network,
38+
haskoinProvider: new HaskoinProvider(
39+
getHaskoinBTCApiUrl()[network],
40+
BTCChain,
41+
AssetBTC,
42+
BTC_DECIMAL,
43+
HaskoinNetwork.BTC
44+
)
45+
}
46+
const client = new BitcoinClient(btcInitParams)
4047
return RD.success(client)
4148
} catch (error) {
4249
console.error('Failed to create BTC client', error)

src/renderer/services/bitcoincash/common.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import * as RD from '@devexperts/remote-data-ts'
2-
import { BCHChain, Client as BitcoinCashClient } from '@xchainjs/xchain-bitcoincash'
2+
import { BCHChain, Client as BitcoinCashClient, defaultBCHParams } from '@xchainjs/xchain-bitcoincash'
33
import * as FP from 'fp-ts/lib/function'
44
import * as O from 'fp-ts/lib/Option'
55
import * as Rx from 'rxjs'
66
import { Observable } from 'rxjs'
77
import * as RxOp from 'rxjs/operators'
88
import { map, shareReplay } from 'rxjs/operators'
99

10-
import { getHaskoinBCHApiUrl } from '../../../shared/api/haskoin'
1110
import { isError } from '../../../shared/utils/guard'
1211
import { clientNetwork$ } from '../app/service'
1312
import * as C from '../clients'
@@ -31,11 +30,12 @@ const clientState$: ClientState$ = FP.pipe(
3130
getPhrase(keystore),
3231
O.map<string, ClientState>((phrase) => {
3332
try {
34-
const client = new BitcoinCashClient({
35-
network,
36-
haskoinUrl: getHaskoinBCHApiUrl(),
37-
phrase
38-
})
33+
const bchInitParams = {
34+
...defaultBCHParams,
35+
phrase: phrase,
36+
network: network
37+
}
38+
const client = new BitcoinCashClient(bchInitParams)
3939
return RD.success(client)
4040
} catch (error) {
4141
return RD.failure<Error>(isError(error) ? error : new Error('Failed to create BCH client'))

src/renderer/services/doge/common.ts

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import * as RD from '@devexperts/remote-data-ts'
2-
import { Client as DogeClient, DOGEChain } from '@xchainjs/xchain-doge'
2+
import { Client as DogeClient, defaultDogeParams, DOGEChain } from '@xchainjs/xchain-doge'
33
import * as FP from 'fp-ts/lib/function'
44
import * as O from 'fp-ts/lib/Option'
55
import * as Rx from 'rxjs'
66
import { Observable } from 'rxjs'
77
import * as RxOp from 'rxjs/operators'
88

9-
import { getBlockcypherUrl } from '../../../shared/api/blockcypher'
10-
import { getSochainUrl } from '../../../shared/api/sochain'
119
import { isError } from '../../../shared/utils/guard'
1210
import { clientNetwork$ } from '../app/service'
1311
import * as C from '../clients'
@@ -31,12 +29,12 @@ const clientState$: ClientState$ = FP.pipe(
3129
getPhrase(keystore),
3230
O.map<string, ClientState>((phrase) => {
3331
try {
34-
const client = new DogeClient({
35-
sochainUrl: getSochainUrl(),
36-
blockcypherUrl: getBlockcypherUrl(),
37-
network,
38-
phrase
39-
})
32+
const dogeInitParams = {
33+
...defaultDogeParams,
34+
network: network,
35+
phrase: phrase
36+
}
37+
const client = new DogeClient(dogeInitParams)
4038
return RD.success(client)
4139
} catch (error) {
4240
console.error('Failed to create DOGE client', error)

0 commit comments

Comments
 (0)