Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'ledgerhq/develop' into HEAD
Browse files Browse the repository at this point in the history
  • Loading branch information
hakim-adamik committed May 12, 2022
2 parents 44e10d7 + a621f96 commit 991ff42
Show file tree
Hide file tree
Showing 42 changed files with 3,268 additions and 12,069 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/bot-staging-explorer-btc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
ref:
description: "Which ref (branch or tag) to pull from ?"
required: false
default: master
default: develop

jobs:
start-runner:
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
env:
SHOW_LEGACY_NEW_ACCOUNT: "1"
DEBUG_HTTP_RESPONSE: "1"
SEED: ${{ secrets.SEED4 }}
SEED: ${{ secrets.SEED2 }}
BOT_REPORT_FOLDER: botreport
VERBOSE_FILE: botreport/logs.txt
GITHUB_SHA: ${GITHUB_SHA}
Expand All @@ -79,9 +79,6 @@ jobs:
EXPLORER: https://explorers.api-01.live.ledger-stg.com
run: mkdir botreport; COINAPPS=$PWD/coin-apps yarn ci-test-bot
timeout-minutes: 120
- name: Run coverage
if: failure() || success()
run: CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} npx codecov
- name: upload logs
if: failure() || success()
uses: actions/upload-artifact@v1
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/bot-staging-explorer-eth.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
ref:
description: "Which ref (branch or tag) to pull from ?"
required: false
default: master
default: develop

jobs:
start-runner:
Expand Down Expand Up @@ -79,9 +79,6 @@ jobs:
EXPLORER: https://explorers.api-01.live.ledger-stg.com
run: mkdir botreport; COINAPPS=$PWD/coin-apps yarn ci-test-bot
timeout-minutes: 120
- name: Run coverage
if: failure() || success()
run: CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} npx codecov
- name: upload logs
if: failure() || success()
uses: actions/upload-artifact@v1
Expand Down
1 change: 1 addition & 0 deletions dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ yarn upgrade-interactive -i --latest
|winston | logs | monthly |
|xstate | generic helper for React | **TBD why it's needed.** |
|zcash-bitcore-lib | Bitcoin coin integration | monthly |
|varuint-bitcoin | Bitcoin coin integration | monthly |
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"stellar-sdk": "^10.0.1",
"superstruct": "^0.14.2",
"triple-beam": "^1.3.0",
"varuint-bitcoin": "1.1.2",
"winston": "^3.4.0",
"xstate": "^4.28.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import coininfo from "coininfo";
import BigNumber from "bignumber.js";
import { DerivationModes } from "../../../../families/bitcoin/wallet-btc/types";
import Xpub from "../../../../families/bitcoin/wallet-btc/xpub";
import Doge from "../../../../families/bitcoin/wallet-btc/crypto/doge";
import BitcoinLikeExplorer from "../../../../families/bitcoin/wallet-btc/explorer";
import BitcoinLikeStorage from "../../../../families/bitcoin/wallet-btc/storage";
import { Merge } from "../../../../families/bitcoin/wallet-btc/pickingstrategies/Merge";
import BitcoinLikeWallet from "../../../../families/bitcoin/wallet-btc/wallet";
import MockBtc from "../../../../mock/Btc";

describe("testing dogecoin transactions", () => {
const wallet = new BitcoinLikeWallet();
const explorer = new BitcoinLikeExplorer({
explorerURI: "https://explorers.api.vault.ledger.com/blockchain/v3/doge",
explorerVersion: "v3",
disableBatchSize: true,
});

const network = coininfo.dogecoin.main.toBitcoinJS();
const crypto = new Doge({ network });

const storage = new BitcoinLikeStorage();
const xpub = new Xpub({
storage,
explorer,
crypto,
xpub: "dgub8rBf7BYsf5YoMezYuPaEhc2tsr7sQA2v2xNCj4mt1czF1m4hRiBdjYeAq5xDVQhN5HqYQnxv2DwyfmDvp1QEfmi44b8uynPL45KXQJrsoi8",
derivationMode: DerivationModes.LEGACY,
});
it("testing dogecoin transactions with huge amount", async () => {
const utxoPickingStrategy = new Merge(xpub.crypto, xpub.derivationMode, []);
const changeAddress = await xpub.getNewAddress(1, 0);
xpub.storage.appendTxs([
{
id: "c4ee70c30b9c5c5fed60c37ce86046156af3623f32aa5be94556b35dcf0af147",
inputs: [],
outputs: [
{
output_index: 0,
value: "500000000000000000", // huge utxo
address: "mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb",
output_hash:
"c4ee70c30b9c5c5fed60c37ce86046156af3623f32aa5be94556b35dcf0af147",
block_height: 1,
rbf: false,
},
{
output_index: 1,
value: "0",
address: "<unknown>",
output_hash:
"c4ee70c30b9c5c5fed60c37ce86046156af3623f32aa5be94556b35dcf0af147",
block_height: 1,
rbf: false,
},
],
block: {
hash: "73c565a6f226978df23480e440b27eb02f307855f50aa3bc72ebb586938f23e0",
height: 1,
time: "2021-07-28T13:34:17Z",
},
account: 0,
index: 0,
address: "mwXTtHo8Yy3aNKUUZLkBDrTcKT9qG9TqLb",
received_at: "2021-07-28T13:34:17Z",
},
]);

const txInfo = await xpub.buildTx({
destAddress: "D9fSjc6zAyjdRgSfbfMLv5z5FpuacvguUi",
amount: new BigNumber(200000000000000000),
feePerByte: 100,
changeAddress,
utxoPickingStrategy,
sequence: 0,
});
const account = await wallet.generateAccount({
xpub: xpub.xpub,
path: "44'/0'",
index: 0,
currency: "dogecoin",
network: "mainnet",
derivationMode: DerivationModes.LEGACY,
explorer: "ledgerv3",
explorerURI: "https://explorers.api.vault.ledger.com/blockchain/v3/doge",
storage: "mock",
storageParams: [],
});
await wallet.signAccountTx({
btc: new MockBtc(),
fromAccount: account,
txInfo,
});
}, 100000);
});
2 changes: 1 addition & 1 deletion src/__tests__/test-helpers/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import BigNumber from "bignumber.js";
import { setSupportedCurrencies } from "../../currencies";
import { setPlatformVersion } from "../../platform/version";

jest.setTimeout(240000);
jest.setTimeout(360000);

expect.extend({
toBeBigNumber(value) {
Expand Down
2 changes: 1 addition & 1 deletion src/exchange/swap/getProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const getProviders: GetProviders = async () => {
});

if (!res.data.length) {
return new SwapNoAvailableProviders();
throw new SwapNoAvailableProviders();
}

return res.data;
Expand Down
6 changes: 4 additions & 2 deletions src/families/bitcoin/getAccountNetworkInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ export async function getAccountNetworkInfo(
}
// Fix fees if suggested fee is too low, this is only for viacoin/decred because the fees backend endpoint is broken
if (
(account.currency.id === "viacoin" || account.currency.id === "decred") &&
(account.currency.id === "viacoin" ||
account.currency.id === "decred" ||
account.currency.id === "qtum") &&
feesPerByte[2].toNumber() < Math.ceil(relayFee * 100000)
) {
feesPerByte[2] = new BigNumber(Math.ceil(relayFee * 100000)).plus(1);
feesPerByte[2] = new BigNumber(Math.ceil(relayFee * 100000)).plus(2);
feesPerByte[1] = feesPerByte[2].plus(1);
if (feesPerByte[1].plus(1).gt(feesPerByte[0])) {
feesPerByte[0] = feesPerByte[1].plus(1);
Expand Down
9 changes: 4 additions & 5 deletions src/families/bitcoin/specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ import { pickSiblings } from "../../bot/specs";
import { bitcoinPickingStrategy } from "./types";
import type { MutationSpec, AppSpec } from "../../bot/types";
import { LowerThanMinimumRelayFee } from "../../errors";
import {
getMinRelayFee,
getUTXOStatus,
bchToCashaddrAddressWithoutPrefix,
} from "./logic";
import { getMinRelayFee, getUTXOStatus } from "./logic";
import { DeviceModelId } from "@ledgerhq/devices";
type Arg = Partial<{
minimalAmount: BigNumber;
Expand Down Expand Up @@ -316,6 +312,9 @@ const bitcoinGold: AppSpec<Transaction> = {
mutations: bitcoinLikeMutations(),
};

const bchToCashaddrAddressWithoutPrefix = (recipient) =>
bchaddrjs.toCashAddress(recipient).split(":")[1];

const bitcoinCash: AppSpec<Transaction> = {
name: "Bitcoin Cash",
currency: getCryptoCurrencyById("bitcoin_cash"),
Expand Down
8 changes: 8 additions & 0 deletions src/families/bitcoin/wallet-btc/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Currency, ICrypto } from "./crypto/types";
import cryptoFactory from "./crypto/factory";
import { fallbackValidateAddress } from "./crypto/base";
import { UnsupportedDerivation } from "../../../errors";
import varuint from "varuint-bitcoin";

export function parseHexString(str: any) {
const result: Array<number> = [];
Expand Down Expand Up @@ -261,3 +262,10 @@ export function isTaprootAddress(address: string, currency?: Currency) {
return false;
}
}

export function writeVarInt(buffer: Buffer, i: number, offset: number) {
// refer to https://github.com/bitcoinjs/bitcoinjs-lib/blob/1f44f722d30cd14a1861c8546e6b455f73862c1e/src/bufferutils.js#L78
varuint.encode(i, buffer, offset);
offset += varuint.encode.bytes;
return offset;
}
36 changes: 24 additions & 12 deletions src/families/bitcoin/wallet-btc/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
// @ts-ignore
import { flatten } from "lodash";
import BigNumber from "bignumber.js";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { BufferWriter } from "bitcoinjs-lib/src/bufferutils";

import Btc from "@ledgerhq/hw-app-btc";
import { log } from "@ledgerhq/logs";
import { Transaction } from "@ledgerhq/hw-app-btc/lib/types";
import { Currency } from "./crypto/types";

import { TransactionInfo, DerivationModes } from "./types";
import { Account, SerializedAccount } from "./account";
import Xpub from "./xpub";
Expand Down Expand Up @@ -246,16 +241,33 @@ class BitcoinLikeWallet {
length += 2 * txInfo.outputs.length;
}
const buffer = Buffer.allocUnsafe(length);
const bufferWriter = new BufferWriter(buffer, 0);
bufferWriter.writeVarInt(txInfo.outputs.length);
let bufferOffset = 0;
bufferOffset = utils.writeVarInt(
buffer,
txInfo.outputs.length,
bufferOffset
);
txInfo.outputs.forEach((txOut) => {
// xpub splits output into smaller outputs than SAFE_MAX_INT anyway
bufferWriter.writeUInt64(txOut.value.toNumber());
// refer to https://github.com/bitcoinjs/bitcoinjs-lib/blob/59b21162a2c4645c64271ca004c7a3755a3d72fb/ts_src/bufferutils.ts#L26
buffer.writeUInt32LE(
txOut.value.modulo(new BigNumber(0x100000000)).toNumber(),
bufferOffset
);
buffer.writeUInt32LE(
txOut.value.dividedToIntegerBy(new BigNumber(0x100000000)).toNumber(),
bufferOffset + 4
);
bufferOffset += 8;
if (additionals && additionals.includes("decred")) {
bufferWriter.writeVarInt(0);
bufferWriter.writeVarInt(0);
bufferOffset = utils.writeVarInt(buffer, 0, bufferOffset);
bufferOffset = utils.writeVarInt(buffer, 0, bufferOffset);
}
bufferWriter.writeVarSlice(txOut.script);
bufferOffset = utils.writeVarInt(
buffer,
txOut.script.length,
bufferOffset
);
bufferOffset += txOut.script.copy(buffer, bufferOffset);
});
const outputScriptHex = buffer.toString("hex");
const associatedKeysets = txInfo.associatedDerivations.map(
Expand Down
Loading

1 comment on commit 991ff42

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 1 txs ($2.40) for Bot 'Hedera'

⚠️ 1 mutations uncovered

Details of the 1 mutations

Spec Hedera (3)

Spec Hedera found 3 Hedera accounts. Will use Hedera 1.0.8 on nanoS 2.1.0
(2071ms) Hedera 1 cross: 0.0000676 HBAR (5ops) (0.0.751515 on 44/3030) hederaBip44#0 js:2:hedera:0.0.751515:hederaBip44
(743ms) Hedera 2: 0.0009109 HBAR (25ops) (0.0.751518 on 44/3030) hederaBip44#1 js:2:hedera:0.0.751518:hederaBip44
(833ms) Hedera 3: 29.974 HBAR (25ops) (0.0.751521 on 44/3030) hederaBip44#2 js:2:hedera:0.0.751521:hederaBip44
all accounts sync in 656ms
▬ Hedera 1.0.8 on nanoS 2.1.0
→ FROM Hedera 3: 29.974 HBAR (25ops) (0.0.751521 on 44/3030) hederaBip44#2 js:2:hedera:0.0.751521:hederaBip44 (! sum of ops 7.67366289 HBAR)
max spendable ~29.973
★ using mutation 'Send ~50%'
→ TO Hedera 2: 0.0009109 HBAR (25ops) (0.0.751518 on 44/3030) hederaBip44#1 js:2:hedera:0.0.751518:hederaBip44
✔️ transaction SEND 14.85332391 HBAR
TO 0.0.751518
STATUS (7ms)
  amount: 14.85332391 HBAR
  estimated fees: 0.000833 HBAR
  total spent: 14.85415691 HBAR
✔️ has been signed! (3s) 
✔️ broadcasted! (294ms) optimistic operation: 
  -14.85332391 HBAR  OUT        NeS1Q7_rn7ZmT-XYPqXJZcLy6Wh3BKhaATE_QFm1PRpM84QoyT5fPXa0b2Qr8vVh 2022-05-12T07:49
✔️ operation confirmed (11.1s): 
  -14.85463584 HBAR  OUT        NeS1Q7_rn7ZmT-XYPqXJZcLy6Wh3BKhaATE_QFm1PRpM84QoyT5fPXa0b2Qr8vVh 2022-05-12T07:49
✔️ Hedera 3: 15.12 HBAR (26ops) (0.0.751521 on 44/3030) hederaBip44#2 js:2:hedera:0.0.751521:hederaBip44 (! sum of ops -7.18097295 HBAR)
(final state reached in 11.1s)


Details of the 1 uncovered mutations

Spec Hedera (1)

  • Send max: Balance is too low (2)

Portfolio ($2.40)

Details of the 1 currencies
Spec (accounts) Operations Balance funds?
Hedera (2) 57 (+2) 29.975 HBAR (- 0.0013119) ($2.40) 💪 0.0.751515

Please sign in to comment.