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

Commit

Permalink
feature/bigint (#38)
Browse files Browse the repository at this point in the history
* replace bitcoinjs-lib-zcash with trezor-utxo-lib

* add missing flowtype

* flow fixes in socketio-worker

* zcash fixes in derive-analysis

* test fixes in zcash "network" fields

* discovery: working with strings (value, balance, received)

* discovery: change test/fixtures values from number to string

* use BigInteger.ZERO instead of new BigInteger('0')

* update monitor-account.json fixtures in tests (negative values to string)

* buildtx: working with strings

* buildtx: update test fixtures

* buildtx: update coinselect test utils

* trezor-utxo-lib: add missing flowtype

* eslint fixes

* fix coverage

* buildtx: fix outputComparator in"createTransaction"

* test fixtures: fee, feeRate and feePerByte to string

* buildtx: working with fee, feeRate and feePerByte as string

* add missing strings to test/fixtures

* buildtx tests: change "deepEqual" to "deepStrictEqual"

* buildtx: convert "fee" response into string

* buildtx: add DOGE test (value > Number.MAX_SAFE_INTEGER)

* add dicover-account test with utxo value > Number.MAX_SAFE_INTEGER

* change npm packages

- replace bitcoinjs-lib-zcash by trezor-utxo-lib
- add bigi@^1.4.0

* change discovery transaction version to 6

* eslint fix

* change example backend urls

* update dependencies

* remove unnecessary import

* update example

* remove unused import from example

* remove wasm file from ./gh_pages

* update trezor-utxo-lib

* request Transaction values as strings

* flow fix

* fix trezor-utxo-lib flowtype

* fix buildtx transaction flowtype

* move invalidTranaction field

* estimateSmartTxFees and estimateTxFees return strings

* Update trezor-utxo-lib.js

* flow fixes

* import trezor-utxo-lib package from npm

* Use bignumber.js library to handle large numbers

* Add new @trezor/utxo-lib

* replace bitcoinjs-lib-zcash with trezor-utxo-lib

* add missing flowtype

* flow fixes in socketio-worker

* zcash fixes in derive-analysis

* test fixes in zcash "network" fields

* discovery: working with strings (value, balance, received)

* discovery: change test/fixtures values from number to string

* use BigInteger.ZERO instead of new BigInteger('0')

* update monitor-account.json fixtures in tests (negative values to string)

* buildtx: working with strings

* buildtx: update test fixtures

* buildtx: update coinselect test utils

* trezor-utxo-lib: add missing flowtype

* eslint fixes

* fix coverage

* buildtx: fix outputComparator in"createTransaction"

* test fixtures: fee, feeRate and feePerByte to string

* buildtx: working with fee, feeRate and feePerByte as string

* add missing strings to test/fixtures

* buildtx tests: change "deepEqual" to "deepStrictEqual"

* buildtx: convert "fee" response into string

* buildtx: add DOGE test (value > Number.MAX_SAFE_INTEGER)

* add dicover-account test with utxo value > Number.MAX_SAFE_INTEGER

* change npm packages

- replace bitcoinjs-lib-zcash by trezor-utxo-lib
- add bigi@^1.4.0

* change discovery transaction version to 6

* eslint fix

* change example backend urls

* update dependencies

* remove unnecessary import

* update example

* remove unused import from example

* remove wasm file from ./gh_pages

* update trezor-utxo-lib

* request Transaction values as strings

* flow fix

* fix trezor-utxo-lib flowtype

* fix buildtx transaction flowtype

* move invalidTranaction field

* estimateSmartTxFees and estimateTxFees return strings

* Update trezor-utxo-lib.js

* flow fixes

* import trezor-utxo-lib package from npm

* Use bignumber.js library to handle large numbers

* Add new @trezor/utxo-lib

* Update yarn.lock

* Update @trezor/utxo-lib, bump version

* Update yarn.lock
  • Loading branch information
szymonlesisz authored and TomasZorvan committed Dec 11, 2019
1 parent d304fa3 commit e73d2c5
Show file tree
Hide file tree
Showing 52 changed files with 8,296 additions and 5,372 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gh-pages/socket-worker.js
gh-pages/trezor-crypto.js
gh-pages/example.js.map
gh-pages/fastxpub.js
gh-pages/fastxpub.wasm
.nyc_output

# Npm library
Expand Down
46 changes: 28 additions & 18 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/* global Worker:false, fetch:false, window:false, document:false */
import { networks } from 'bitcoinjs-lib-zcash';


// eslint-disable-next-line import/no-extraneous-dependencies
import h from 'virtual-dom/h';
Expand All @@ -22,7 +20,8 @@ const socketWorkerFactory = () => new Worker('./socket-worker.js');
const discoveryWorkerFactory = () => new Worker('./discovery-worker.js');

function renderTx(tx) {
return h('tr', [
const className = tx.invalidTransaction ? 'invalid' : 'valid';
return h('tr', { className }, [
h('td', tx.hash),
h('td', tx.height ? tx.height.toString() : 'unconfirmed'),
h('td', tx.value.toString()),
Expand All @@ -33,9 +32,16 @@ function renderTx(tx) {

function renderAccount(account) {
if (typeof account.info === 'number') {
return h('div', `${account.xpub} - Loading (${account.info} transactions)`);
return [
h('h3', `${account.xpub}`),
h('div', `Loading ${account.info} transactions)`),
];
}
return [h('div', `${account.xpub} - Balance: ${account.info.balance}`), h('table', account.info.transactions.map(renderTx))];
return [
h('h3', `${account.xpub}`),
h('div', `Balance: ${account.info.balance}`),
h('table', account.info.transactions.map(renderTx)),
];
}

function render(state) {
Expand All @@ -56,10 +62,10 @@ function refresh() {
tree = newTree;
}

function discover(xpubs, discovery, network) {
function discover(xpubs, discovery, network, segwit, cashaddr) {
let done = 0;
xpubs.forEach((xpub, i) => {
const process = discovery.discoverAccount(null, xpub, network, 'off');
const process = discovery.discoverAccount(null, xpub, network, segwit ? 'p2sh' : 'off', cashaddr, 20, 0);
appState[i] = { xpub, info: 0 };

process.stream.values.attach((status) => {
Expand All @@ -80,29 +86,33 @@ function discover(xpubs, discovery, network) {
console.time('portfolio');
}

window.run = () => {
const XPUBS = [
'xpub6BiVtCpG9fQQ8pVjVF7jm3kLahkNbQRkWGUvzsKQpXWYvhYD4d4UDADxZUL4xp9UwsDT5YgwNKofTWRtwJgnHkbNxuzLDho4mxfS9KLesGP',
'xpub6BiVtCpG9fQQCgxA541qm9qZ9VrGLScde4zsAMj2d15ewiMysCAnbgvSDSZXhFUdsyA2BfzzMrMFJbC4VSkXbzrXLZRitAmUVURmivxxqMJ',
'xpub6BiVtCpG9fQQDvwDNekCEzAr3gYcoGXEF27bMwSBsCVP3bJYdUZ6m3jhv9vSG7hVxff3VEfnfK4fcMr2YRwfTfHcJwM4ioS6Eiwnrm1wcuf',
'xpub6BiVtCpG9fQQGq7bXBjjf5zyguEXHrmxDu4t7pdTFUtDWD5epi4ecKmWBTMHvPQtRmQnby8gET7ArTzxjL4SNYdD2RYSdjk7fwYeEDMzkce',
];

const BITCORE_URLS = ['https://bitcore1.trezor.io', 'https://bitcore3.trezor.io'];
window.run = () => {
window.clear();
const XPUBS = document.getElementById('xpubs').value.split(';');
const BITCORE_URLS = document.getElementById('urls').value.split(';');
const selected = document.getElementById('network').value;
const d = window.data[selected];

const blockchain = new BitcoreBlockchain(BITCORE_URLS, socketWorkerFactory);
const blockchain = new BitcoreBlockchain(BITCORE_URLS, socketWorkerFactory, d.network);

const discovery = new WorkerDiscovery(
discoveryWorkerFactory,
fastXpubWorker,
fastXpubWasmFilePromise,
blockchain,
);
const network = networks.bitcoin;
discover(XPUBS, discovery, network);
const cashaddr = selected === 'bitcoincash';
const segwit = selected.indexOf('Segwit') >= 0;
discover(XPUBS, discovery, d.network, segwit, cashaddr);
};

window.stop = () => {
processes.forEach(p => p.dispose());
console.timeEnd('portfolio');
};

window.clear = () => {
appState.splice(0, appState.length);
refresh();
};
40 changes: 33 additions & 7 deletions gh-pages/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,40 @@
</head>
<body>
<style>
table, tr, td { border: 1px solid black; }
table { border-bottom: 10px solid red; }
table {
border-spacing: 0;
border: 0px;
border-collapse: collapse;
}
tr:nth-child(even) {
background: #efefef;
}
td, th {
border: 1px solid black;
padding: 4px;
}
label, textarea, select { display: block; margin-bottom: 10px; }
textarea { width: 100%; height: 50px; }
h3 {
margin: 10px 0 0 0;
}
.invalid { background: red; }
.balance { }

</style>
Library version 6.0.0
<center>
<button autofocus onclick="run()">discover</button><br><br>
<button onclick="stop()">stop</button>
</center>
hd-wallet Library version 9.0.0
<div>
<br/>
Xpubs, separated by ";"
<textarea id="xpubs"></textarea>
Backend urls, separated by ";"
<textarea id="urls"></textarea>
<select id="network"></select>
<button autofocus onclick="window.run()">discover</button>
<button onclick="window.stop()">stop</button>
<button onclick="window.clear()">clear</button>
</div>
<script src="example.js"></script>
<script src="ui.js"></script>
</body>
</html>
Binary file modified gh-pages/fastxpub.wasm
Binary file not shown.

0 comments on commit e73d2c5

Please sign in to comment.