Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Issue 2535 - Can't get UTXO Balance #2536

Merged
merged 8 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ yarn-error.log*
# don't share .env, but .env.sample
.env

# don't need to share yarn.lock
yarn.lock

dev-app-update.yml
/.idea/
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.19.1 (2023-04-XX)

# Internal

-Updates/refactor to support latest xchain updates for UTXO support. Keystore clients and ledger code updated.

# 1.19.0 (2023-01-xx)

## Add
Expand Down
19 changes: 10 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "asgardex",
"productName": "ASGARDEX",
"version": "1.18.6",
"version": "1.19.1-alpha",
"description": "WALLET AND EXCHANGE CLIENT FOR THORCHAIN",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -88,16 +88,17 @@
"@thorchain/ledger-thorchain": "^0.1.0-alpha.2",
"@types/electron-devtools-installer": "^2.2.2",
"@xchainjs/xchain-binance": "^5.6.7",
"@xchainjs/xchain-bitcoin": "^0.20.8",
"@xchainjs/xchain-bitcoincash": "^0.15.7",
"@xchainjs/xchain-client": "^0.13.5",
"@xchainjs/xchain-cosmos": "0.20.7",
"@xchainjs/xchain-crypto": "^0.2.6",
"@xchainjs/xchain-doge": "^0.5.7",
"@xchainjs/xchain-bitcoin": "^0.21.1",
"@xchainjs/xchain-bitcoincash": "^0.15.9",
"@xchainjs/xchain-client": "^0.13.6",
"@xchainjs/xchain-cosmos": "0.20.8",
"@xchainjs/xchain-crypto": "^0.2.7",
"@xchainjs/xchain-doge": "^0.5.10",
"@xchainjs/xchain-ethereum": "^0.27.7",
"@xchainjs/xchain-litecoin": "^0.10.9",
"@xchainjs/xchain-thorchain": "^0.27.8",
"@xchainjs/xchain-litecoin": "^0.11.1",
"@xchainjs/xchain-thorchain": "^0.27.9",
"@xchainjs/xchain-util": "^0.12.0",
"@xchainjs/xchain-utxo-providers": "^0.1.1",
"antd": "^4.20.7",
"axios": "^0.25.0",
"bchaddrjs": "^0.5.2",
Expand Down
31 changes: 21 additions & 10 deletions src/main/api/ledger/bitcoin/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import AppBTC from '@ledgerhq/hw-app-btc'
import { Transaction } from '@ledgerhq/hw-app-btc/lib/types'
import Transport from '@ledgerhq/hw-transport'
import { broadcastTx, buildTx, LOWER_FEE_BOUND, UPPER_FEE_BOUND } from '@xchainjs/xchain-bitcoin'
import {
AssetBTC,
BTCChain,
Client,
defaultBTCParams,
LOWER_FEE_BOUND,
UPPER_FEE_BOUND
} from '@xchainjs/xchain-bitcoin'
import { checkFeeBounds, FeeRate, TxHash } from '@xchainjs/xchain-client'
import { Address, BaseAmount } from '@xchainjs/xchain-util'
import { HaskoinProvider, HaskoinNetwork } from '@xchainjs/xchain-utxo-providers'
import * as Bitcoin from 'bitcoinjs-lib'
import * as E from 'fp-ts/lib/Either'

import { getHaskoinBTCApiUrl } from '../../../../shared/api/haskoin'
import { getSochainUrl } from '../../../../shared/api/sochain'
import { LedgerError, LedgerErrorId, Network } from '../../../../shared/api/types'
import { toClientNetwork } from '../../../../shared/utils/client'
import { isError } from '../../../../shared/utils/guard'
Expand Down Expand Up @@ -63,19 +70,19 @@ export const send = async ({
*/
const spendPendingUTXO = !memo

const haskoinUrl = getHaskoinBTCApiUrl()[network]
const btcInitParams = {
...defaultBTCParams,
network: clientNetwork
}
const btcClient = new Client(btcInitParams)

const { psbt, utxos } = await buildTx({
const { psbt, utxos } = await btcClient.buildTx({
amount,
recipient,
memo,
feeRate,
sender,
network: clientNetwork,
sochainUrl: getSochainUrl(),
haskoinUrl,
spendPendingUTXO,
withTxHex: true
spendPendingUTXO
})

const inputs: Array<[Transaction, number, string | null, number | null]> = utxos.map(({ txHex, hash, index }) => {
Expand All @@ -102,7 +109,11 @@ export const send = async ({
useTrustedInputForSegwit: true,
additionals: ['bech32']
})
const txHash = await broadcastTx({ txHex, haskoinUrl })

const haskoinUrl = getHaskoinBTCApiUrl()[network] //https://haskoin.ninerealms.com
const haskoinProvider = new HaskoinProvider(haskoinUrl, BTCChain, AssetBTC, 8, HaskoinNetwork.BTC)

const txHash = await haskoinProvider.broadcastTx(txHex)

if (!txHash) {
return E.left({
Expand Down
26 changes: 20 additions & 6 deletions src/main/api/ledger/bitcoincash/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import AppBTC from '@ledgerhq/hw-app-btc'
import { Transaction } from '@ledgerhq/hw-app-btc/lib/types'
import Transport from '@ledgerhq/hw-transport'
import { broadcastTx, buildTx, LOWER_FEE_BOUND, UPPER_FEE_BOUND } from '@xchainjs/xchain-bitcoincash'
import {
AssetBCH,
BCHChain,
Client,
defaultBCHParams,
LOWER_FEE_BOUND,
UPPER_FEE_BOUND
} from '@xchainjs/xchain-bitcoincash'
import { checkFeeBounds, FeeRate, TxHash } from '@xchainjs/xchain-client'
import { Address, BaseAmount } from '@xchainjs/xchain-util'
import { HaskoinProvider, HaskoinNetwork } from '@xchainjs/xchain-utxo-providers'
import * as Bitcoin from 'bitcoinjs-lib'
import * as E from 'fp-ts/lib/Either'

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

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

const { builder, inputs: txInputs } = await buildTx({
const bchInitParams = {
...defaultBCHParams,
network: clientNetwork
}

const bchClient = new Client(bchInitParams)

const { builder, inputs: txInputs } = await bchClient.buildTx({
amount,
recipient,
memo,
feeRate,
sender,
network: clientNetwork,
haskoinUrl
sender
})

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

const txHash = await broadcastTx({ txHex, haskoinUrl })
const txHash = await haskoinProvider.broadcastTx(txHex)

if (!txHash) {
return E.left({
Expand Down
29 changes: 21 additions & 8 deletions src/main/api/ledger/doge/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import AppBTC from '@ledgerhq/hw-app-btc'
import { Transaction } from '@ledgerhq/hw-app-btc/lib/types'
import Transport from '@ledgerhq/hw-transport'
import { checkFeeBounds, FeeRate, TxHash } from '@xchainjs/xchain-client'
import { broadcastTx, buildTx, getSendTxUrl, LOWER_FEE_BOUND, UPPER_FEE_BOUND } from '@xchainjs/xchain-doge'
import {
AssetDOGE,
Client,
DOGEChain,
getSendTxUrl,
LOWER_FEE_BOUND,
UPPER_FEE_BOUND,
defaultDogeParams
} from '@xchainjs/xchain-doge'
import { Address, BaseAmount } from '@xchainjs/xchain-util'
import { BlockcypherProvider, BlockcypherNetwork } from '@xchainjs/xchain-utxo-providers'
import * as E from 'fp-ts/lib/Either'

import { getBlockcypherUrl } from '../../../../shared/api/blockcypher'
import { getSochainUrl } from '../../../../shared/api/sochain'
import { LedgerError, LedgerErrorId, Network } from '../../../../shared/api/types'
import { toClientNetwork } from '../../../../shared/utils/client'
import { isError } from '../../../../shared/utils/guard'
Expand Down Expand Up @@ -54,15 +62,19 @@ export const send = async ({
const clientNetwork = toClientNetwork(network)
const derivePath = getDerivationPath(walletIndex, clientNetwork)

const { psbt, utxos } = await buildTx({
const dogeInitParams = {
...defaultDogeParams,
network: clientNetwork
}

const dogeClient = new Client(dogeInitParams)

const { psbt, utxos } = await dogeClient.buildTx({
amount,
recipient,
memo,
feeRate,
sender,
network: clientNetwork,
sochainUrl: getSochainUrl(),
withTxHex: true
sender
})

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

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

const txHash = await broadcastTx({ network: clientNetwork, txHex, nodeUrl })
const txHash = await blockcypherProvider.broadcastTx(txHex)

if (!txHash) {
return E.left({
Expand Down
16 changes: 9 additions & 7 deletions src/main/api/ledger/litecoin/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ import AppBTC from '@ledgerhq/hw-app-btc'
import { Transaction } from '@ledgerhq/hw-app-btc/lib/types'
import Transport from '@ledgerhq/hw-transport'
import { checkFeeBounds, FeeRate, TxHash } from '@xchainjs/xchain-client'
import { broadcastTx, buildTx, LOWER_FEE_BOUND, UPPER_FEE_BOUND } from '@xchainjs/xchain-litecoin'
import { broadcastTx, Client, defaultLTCParams, LOWER_FEE_BOUND, UPPER_FEE_BOUND } from '@xchainjs/xchain-litecoin'
import { Address, BaseAmount } from '@xchainjs/xchain-util'
import * as Bitcoin from 'bitcoinjs-lib'
import * as E from 'fp-ts/lib/Either'

import { getLTCNodeAuth, getLTCNodeUrl } from '../../../../shared/api/litecoin'
import { getSochainUrl } from '../../../../shared/api/sochain'
import { LedgerError, LedgerErrorId, Network } from '../../../../shared/api/types'
import { toClientNetwork } from '../../../../shared/utils/client'
import { isError } from '../../../../shared/utils/guard'
Expand Down Expand Up @@ -55,15 +54,18 @@ export const send = async ({
const clientNetwork = toClientNetwork(network)
const derivePath = getDerivationPath(walletIndex, clientNetwork)

const { psbt, utxos } = await buildTx({
const ltcInitParams = {
...defaultLTCParams,
network: clientNetwork
}
const ltcClient = new Client(ltcInitParams)

const { psbt, utxos } = await ltcClient.buildTx({
amount,
recipient,
memo,
feeRate,
sender,
network: clientNetwork,
sochainUrl: getSochainUrl(),
withTxHex: true
sender
})

const inputs: Array<[Transaction, number, string | null, number | null]> = utxos.map(({ txHex, hash, index }) => {
Expand Down
8 changes: 6 additions & 2 deletions src/renderer/helpers/clientHelper.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Client as BnbClient } from '@xchainjs/xchain-binance'
import { Client as BtcClient } from '@xchainjs/xchain-bitcoin'
import { Client as BtcClient, defaultBTCParams } from '@xchainjs/xchain-bitcoin'

import { MOCK_PHRASE } from '../../shared/mock/wallet'
import { isBnbClient } from './clientHelper'
Expand All @@ -11,7 +11,11 @@ describe('helpers/clientHelper', () => {
expect(isBnbClient(client)).toBeTruthy()
})
it('returns false for BTC client', () => {
const client = new BtcClient({ phrase: MOCK_PHRASE })
const btcInitParams = {
...defaultBTCParams,
phrase: MOCK_PHRASE
}
const client = new BtcClient(btcInitParams)
expect(isBnbClient(client)).toBeFalsy()
})
})
Expand Down
23 changes: 15 additions & 8 deletions src/renderer/services/bitcoin/common.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as RD from '@devexperts/remote-data-ts'
import { BTCChain, Client as BitcoinClient } from '@xchainjs/xchain-bitcoin'
import { AssetBTC, BTCChain, BTC_DECIMAL, Client as BitcoinClient, defaultBTCParams } from '@xchainjs/xchain-bitcoin'
import { HaskoinNetwork, HaskoinProvider } from '@xchainjs/xchain-utxo-providers'
import * as FP from 'fp-ts/lib/function'
import * as O from 'fp-ts/lib/Option'
import * as Rx from 'rxjs'
import { Observable } from 'rxjs'
import * as RxOp from 'rxjs/operators'

import { getHaskoinBTCApiUrl } from '../../../shared/api/haskoin'
import { getSochainUrl } from '../../../shared/api/sochain'
import { isError } from '../../../shared/utils/guard'
import { clientNetwork$ } from '../app/service'
import * as C from '../clients'
Expand All @@ -31,12 +31,19 @@ const clientState$: ClientState$ = FP.pipe(
getPhrase(keystore),
O.map<string, ClientState>((phrase) => {
try {
const client = new BitcoinClient({
network,
phrase,
haskoinUrl: getHaskoinBTCApiUrl(),
sochainUrl: getSochainUrl()
})
const btcInitParams = {
...defaultBTCParams,
phrase: phrase,
network: network,
haskoinProvider: new HaskoinProvider(
getHaskoinBTCApiUrl()[network],
BTCChain,
AssetBTC,
BTC_DECIMAL,
HaskoinNetwork.BTC
)
}
const client = new BitcoinClient(btcInitParams)
return RD.success(client)
} catch (error) {
console.error('Failed to create BTC client', error)
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/services/bitcoincash/common.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import * as RD from '@devexperts/remote-data-ts'
import { BCHChain, Client as BitcoinCashClient } from '@xchainjs/xchain-bitcoincash'
import { BCHChain, Client as BitcoinCashClient, defaultBCHParams } from '@xchainjs/xchain-bitcoincash'
import * as FP from 'fp-ts/lib/function'
import * as O from 'fp-ts/lib/Option'
import * as Rx from 'rxjs'
import { Observable } from 'rxjs'
import * as RxOp from 'rxjs/operators'
import { map, shareReplay } from 'rxjs/operators'

import { getHaskoinBCHApiUrl } from '../../../shared/api/haskoin'
import { isError } from '../../../shared/utils/guard'
import { clientNetwork$ } from '../app/service'
import * as C from '../clients'
Expand All @@ -31,11 +30,12 @@ const clientState$: ClientState$ = FP.pipe(
getPhrase(keystore),
O.map<string, ClientState>((phrase) => {
try {
const client = new BitcoinCashClient({
network,
haskoinUrl: getHaskoinBCHApiUrl(),
phrase
})
const bchInitParams = {
...defaultBCHParams,
phrase: phrase,
network: network
}
const client = new BitcoinCashClient(bchInitParams)
return RD.success(client)
} catch (error) {
return RD.failure<Error>(isError(error) ? error : new Error('Failed to create BCH client'))
Expand Down
16 changes: 7 additions & 9 deletions src/renderer/services/doge/common.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as RD from '@devexperts/remote-data-ts'
import { Client as DogeClient, DOGEChain } from '@xchainjs/xchain-doge'
import { Client as DogeClient, defaultDogeParams, DOGEChain } from '@xchainjs/xchain-doge'
import * as FP from 'fp-ts/lib/function'
import * as O from 'fp-ts/lib/Option'
import * as Rx from 'rxjs'
import { Observable } from 'rxjs'
import * as RxOp from 'rxjs/operators'

import { getBlockcypherUrl } from '../../../shared/api/blockcypher'
import { getSochainUrl } from '../../../shared/api/sochain'
import { isError } from '../../../shared/utils/guard'
import { clientNetwork$ } from '../app/service'
import * as C from '../clients'
Expand All @@ -31,12 +29,12 @@ const clientState$: ClientState$ = FP.pipe(
getPhrase(keystore),
O.map<string, ClientState>((phrase) => {
try {
const client = new DogeClient({
sochainUrl: getSochainUrl(),
blockcypherUrl: getBlockcypherUrl(),
network,
phrase
})
const dogeInitParams = {
...defaultDogeParams,
network: network,
phrase: phrase
}
const client = new DogeClient(dogeInitParams)
return RD.success(client)
} catch (error) {
console.error('Failed to create DOGE client', error)
Expand Down
Loading