Thanks for reviewing. Sorry this PR is so big. I've typed up some notes below that might help your review. I'm also happy to hop on a call to talk through it. Some things in here will be improved in this week's iterations, but I wanted to post something because momentum! Anyway, I'd really welcome all comments or feedback!
bitcore-lib-cash patch
Patched bitcore-lib-cash so that we can use it for kaspa transactions!
This patch meets the requirements of our main workflow. However, should we want to do one of the following things, we could expect the patch will need more attention:
multisig support
adjusting locktime or sequence number
fee estimation (note that kaspa has their own fee estimator api route)
Wallet class
transaction composition
the wallet can compose transactions with composeTx({toAddr, amount, fee?, changeAddrOverride?}). This returns a signed, serialized rawTransaction. The rawTransaction can be used to test against the Kaspa reference implementation implemented in Go (see send.go and the tests).
A composed transaction should set an output to a newly derived address on the change derive path, but the kaspa Go example wallet sets the change address to equal the "utxo from" address. So that the wallet's composeTx can participate in serialization tests, we have a changeAddrOverride parameter. I foresee removing serialization tests from the wallet and letting them reside in the bitcore integration tests only. Then we can remove the otherwise useless changeAddrOverride param.
naive UTXO selection
adds up UTXOs in its utxoSet until it has enough to meet the amount + fee of the transaction.
UTXO set management
takes UTXO array from kaspa API, transforms members into bitcore's UnspentOutput type, stores the array as a class property.
TODO: manage UTXOs that have been spent.
address derivation
the wallet can derive receive addresses or change addresses. Derived address/privateKey pairs are stored as key/value pairs for use during tx sign.
API helpers
Prototyping API helpers for /utxo and /transaction.
started Api type namespace
Tests
Wallet class tests
need more work.
bitcore integration tests
Purpose is to ensure bitcore-lib-cash is playing nice with Kaspa. These feel complete but could be better organized.
API tests
Begin to test kaspa API integration on /utxo and /transaction.
API tests are not run by default, because they are dependent on Kaspa chain state.
Sorry about the really crappy workflow, but if you want to use the test to make a transaction against your local kdx chain, here's how you do it.
patch KDX (Matt has done this, Ben I can help you with the 1 line fix), run KDX, set the mining address to kaspatest:qq0d6h0prjm5mpdld5pncst3adu0yam6xch4tr69k2. Wait for your balance to grow (you can see via the KDX console tab, type wallet balance kaspatest:qq0d6h0prjm5mpdld5pncst3adu0yam6xch4tr69k2). Then comment out line 32 of jest.config.js and run npm run test:unit. The test will retrieve utxos for the above address, add them to the wallet's utxo set, then make a transaction (parameters hardcoded). It's a poor workflow and a poor test, and I look forward to improving it; I just had to see everything connected even if just for a second.
node-fetch polyfill
fetch polyfill used in jest setup so we can do api tests.
config.json
taking a crack at a config file to store app default values
Resolves #18
Thanks for reviewing. Sorry this PR is so big. I've typed up some notes below that might help your review. I'm also happy to hop on a call to talk through it. Some things in here will be improved in this week's iterations, but I wanted to post something because momentum! Anyway, I'd really welcome all comments or feedback!
bitcore-lib-cash patch
Wallet class
transaction composition
composeTx({toAddr, amount, fee?, changeAddrOverride?})
. This returns a signed, serializedrawTransaction
. TherawTransaction
can be used to test against the Kaspa reference implementation implemented in Go (see send.go and the tests).composeTx
can participate in serialization tests, we have achangeAddrOverride
parameter. I foresee removing serialization tests from the wallet and letting them reside in the bitcore integration tests only. Then we can remove the otherwise uselesschangeAddrOverride
param.naive UTXO selection
utxoSet
until it has enough to meet the amount + fee of the transaction.UTXO set management
address derivation
API helpers
/utxo
and/transaction
.Tests
Wallet class tests
bitcore integration tests
API tests
/utxo
and/transaction
.kaspatest:qq0d6h0prjm5mpdld5pncst3adu0yam6xch4tr69k2
. Wait for your balance to grow (you can see via the KDX console tab, typewallet balance kaspatest:qq0d6h0prjm5mpdld5pncst3adu0yam6xch4tr69k2
). Then comment out line 32 of jest.config.js and runnpm run test:unit
. The test will retrieve utxos for the above address, add them to the wallet's utxo set, then make a transaction (parameters hardcoded). It's a poor workflow and a poor test, and I look forward to improving it; I just had to see everything connected even if just for a second.node-fetch polyfill
config.json