-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored Bch & Doge for Client Ledger (#1110)
* Refactored Bch for Client Ledger * refactored doge for ledger client * fix broken test * update package json
- Loading branch information
1 parent
2f7988a
commit 8e82dc3
Showing
22 changed files
with
685 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@xchainjs/xchain-doge': patch | ||
--- | ||
|
||
Refactored package to include LedgerClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@xchainjs/xchain-bitcoincash': patch | ||
--- | ||
|
||
Refactored to suit ClientLedger |
3 changes: 2 additions & 1 deletion
3
packages/xchain-bitcoin/__e2e__/blockcypher.bitcoin-client.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
packages/xchain-bitcoincash/__e2e__/bitcoinCash-ledger-client.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import TransportNodeHid from '@ledgerhq/hw-transport-node-hid' | ||
import { Network } from '@xchainjs/xchain-client' | ||
import { assetAmount, assetToBase } from '@xchainjs/xchain-util' | ||
import { UtxoClientParams } from '@xchainjs/xchain-utxo' | ||
|
||
import { ClientLedger } from '../src/clientLedger' | ||
import { | ||
AssetBCH, | ||
BitgoProviders, | ||
HaskoinDataProviders, | ||
LOWER_FEE_BOUND, | ||
UPPER_FEE_BOUND, | ||
explorerProviders, | ||
} from '../src/const' | ||
jest.setTimeout(200000) | ||
|
||
// Default parameters for Bitcoin Cash (BCH) client | ||
const defaultBchParams: UtxoClientParams = { | ||
network: Network.Mainnet, // Default network is Mainnet | ||
phrase: '', // Default empty phrase | ||
explorerProviders: explorerProviders, // Default explorer providers | ||
dataProviders: [HaskoinDataProviders, BitgoProviders], // Default data providers | ||
rootDerivationPaths: { | ||
[Network.Mainnet]: `m/44'/145'/0'/0/`, // Default root derivation path for Mainnet | ||
[Network.Testnet]: `m/44'/1'/0'/0/`, // Default root derivation path for Testnet | ||
[Network.Stagenet]: `m/44'/145'/0'/0/`, // Default root derivation path for Stagenet | ||
}, | ||
feeBounds: { | ||
lower: LOWER_FEE_BOUND, // Default lower fee bound | ||
upper: UPPER_FEE_BOUND, // Default upper fee bound | ||
}, | ||
} | ||
|
||
describe('BitcoinCash Client Ledger', () => { | ||
let btcCashClient: ClientLedger | ||
beforeAll(async () => { | ||
const transport = await TransportNodeHid.create() | ||
|
||
btcCashClient = new ClientLedger({ | ||
transport, | ||
...defaultBchParams, | ||
}) | ||
}) | ||
it('get ledger address async without verification', async () => { | ||
const address = await btcCashClient.getAddressAsync() | ||
console.log('address', address) | ||
expect(address).toContain('q') | ||
}) | ||
|
||
it('get ledger address async with verification', async () => { | ||
const address = await btcCashClient.getAddressAsync(0, true) | ||
console.log('address', address) | ||
expect(address).toContain('q') | ||
}) | ||
|
||
it('get ledger balance', async () => { | ||
const address = await btcCashClient.getAddressAsync() | ||
const balance = await btcCashClient.getBalance(address) | ||
console.log('balance', balance[0].amount.amount().toString()) | ||
}) | ||
|
||
it('transfer Ledger test amount', async () => { | ||
try { | ||
const to = await btcCashClient.getAddressAsync(1) | ||
const amount = assetToBase(assetAmount('0.001')) | ||
const txid = await btcCashClient.transfer({ | ||
asset: AssetBCH, | ||
recipient: to, | ||
amount, | ||
memo: 'test', | ||
feeRate: 1, | ||
}) | ||
console.log(JSON.stringify(txid, null, 2)) | ||
} catch (err) { | ||
console.error('ERR running test', err) | ||
fail() | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.