Commit Graph

239 Commits

Author SHA1 Message Date
Ben Carman
1731bd3163 Callback rework (#1542) 2020-06-15 17:30:08 -05:00
Chris Stewart
c54d6dcbdc 2020 06 09 addr invoice string factory (#1538)
* Implement StringFactory with Address and LnInvoice

* Address code review

* Run scalafmt
2020-06-11 10:44:12 -05:00
Ben Carman
61d9f0efba Implement best block hash correctly (#1452)
* Implement best block hash correctly

* Handle no common history

* Fix getBlockProof to be BigInt instead of UInt32

* Fix warnings

* Make get best filter use chainwork

* Remove unused function, test isMissingChainWork

* Fix comparisons for chain work in sql

* Fix migrations from rebase

* Fix CI error

* Fix postgresql
2020-06-04 12:05:10 -05:00
Ben Carman
1656b9091f Implement BitcoindRpcClient as a FeeProvider (#1486)
* Implement BitcoindRpcClient as a FeeProvider

* Make FeeRateApi a trait
2020-05-30 09:03:08 -05:00
Ben Carman
c10d5bc89b Fee Rate Api Support (#1470)
* Fee Rate Api Support

* FeeRateProvider Tests

* Rename folder

* Fix docs
2020-05-29 13:01:20 -05:00
Chris Stewart
87c2459c9f Cache numbers between 0 and 256 to make serialization/deserialization faster (#1482) 2020-05-29 05:00:15 -05:00
Nadav Kohen
bc5953b6c8 Rework Standard Finalizer (into pieces) (#1473)
* Made the standard non-interactive tx finalizer simple using composition of its (reusable) pieces

* Responded to code review and made minor improvements

* Fixed docs
2020-05-27 18:05:37 -05:00
Chris Stewart
b036aa3338 Add more optimizations, MultSignatureScriptPubKey.isMultiSignatureScr… (#1475)
* Add more optimizations, MultSignatureScriptPubKey.isMultiSignatureScriptPubKey() fails fast if it's not a valid multisig spk, also use more caching inside of Number's (UInt64, UInt32, etc)

* Fix shortChannelidTest

* Cache popular UInt64 numbers that are used in ScriptPubKey's. This reduces allocations which reduces memory usage
2020-05-27 15:47:20 -05:00
Nadav Kohen
4f2c8f73f1 CryptoContext Refactor (#1469)
* Moved logic to disable use of secp256k1 library into crypto project

* Fixed secp doc
2020-05-26 13:05:21 -05:00
Nadav Kohen
99459745db Fixed sequence computation for P2PKWithTimeout and RawTxFinalizer composition discovered during DLC rebase (#1461) 2020-05-26 07:54:54 -05:00
Ben Carman
f2d98514b7 Implement FeeUnit SatoshisPerKW (#1455) 2020-05-26 06:11:49 -05:00
Ben Carman
192cd49974 Fix fee rate calculation bugs, add tests (#1454)
* Fix fee rate calculation bugs, add tests

* Rounding issues

* Add link

* Change error message
2020-05-25 08:06:37 -05:00
Chris Stewart
40160d9c5f Attempt to optimize block tests more to avoid timeouts (#1459)
* Attempt to optimize block tests more to avoid timeouts

* Fix asm.tail bug

* Make parseRedeemScript just return a ScriptPubKey rather than a Try[ScriptPubKey]

* Make encoding a UInt64 to hex more efficient

* Cache Transaction.bytesSize so we don't need to serialize everything again to estimate the byteSize

* Refactor CryptoBytesUtil.addPadding() and it's usage in UInt64

* Use StringBuilder.append() rather than StringBuilder.addAll() which is not supported in scala 2.11 & 2.12

* Address nadav's code review
2020-05-22 11:15:17 -05:00
Nadav Kohen
dfd3353cc4 TxBuilder Refactor (#1426)
* Refactored Transaction

Created RawTxBuilder

Created RawTxFinalizer as layer on top of RawTxBuilder

Introduced RawTxSigner and replaced TxBuilder!

Deleted TxBuilder!

* fixed things after rebase

* Made RawTxBuilder compatible with older versions of scala

* Began responding to review

* Made Finalizer take a Builder rather than the other way around

* Added composition for finalizers

* Ran scalafmt

* Updated txbuilder example documentation

* Moved tests from old TxBuilderTest files to relevant new test files

* Added scaladocs
2020-05-21 09:47:08 -05:00
Ben Carman
11255390d2 Small optimization for ScriptOperationFactory.operations (#1450)
* Small optimization for ScriptOperationFactory.operations

* Make operations a val
2020-05-20 10:26:00 -05:00
Ben Carman
4942315c9f Fix allowing BytesToPushOntoStack(0) (#1448) 2020-05-19 16:52:58 -05:00
Chris Stewart
bc600c230e 2020 05 17 optimizations (#1435)
* Make ScriptOperationFactory subclasses use a val to cache operaetions rather than operations

* Make ScriptOperation's use a Vector rather than Seq. Seq is a trait that can sometimes be backed by a List which can have some O(n) behavior

* Remove BlockTest benchamarking test case

* Put popular opcodes at beginning of ScriptOperations.operations for an optimization

* Remove Try() allocation on ECPublicKey.isFullyValid()

* Fix how CompactSizeUInt was serialized to be more efficient, move isMultiSig() and isLocktimeSPK() to be inline so we don't evaluate it unless we absolutely need to

* Use Map inside of ScriptOperation.fromByte()

* Update map to look up script operation rather than iterating
2020-05-18 20:23:12 -05:00
Chris Stewart
0ac3328d4b Remove the clause in Transction.fromHex() where we throw in the case … (#1431)
* Remove the clause in Transction.fromHex() where we throw in the case of a witness transaction, do something smarter and look at bytes in the byte vector

* WIP add test case

* Add back try/catch as it's still necessary for cases of unsigned base transactions

* Add permalink to example test case
2020-05-18 14:28:00 -05:00
Nadav Kohen
4eb9980d6b InputInfo Refactor (#1400)
Added OutputReference and introduced public key computation on SPKs

Made InputInfo into an ADT

Made UTXOSpendingInfo use InputInfo

Replaced UTXOSpendingInfo with NewSpendingInfo and got non-test things compiling

Made aliases for (NewSpendingInfo/NewSpendingInfoFull/NewSpendingInfoSingle)[InputInfo]

Got rid of source code mention of UTXOSpendingInfo

sbt compile passes

tests compile

Fixed all coreTest tests

Renamed to UTXOInfo

Some cleanup

Moved redeem script and script witness accessors to companion object

Responded to code review

Added OutputReference and scaladocs

Moved p2pkhPreImageOpt downstream and generalized to hashPreImages

Fixed adding-spks.md

Fixed psbts.md and txbuilder.md

Renamed UTXOInfo

Apply renaming to docs
2020-05-15 11:14:15 -05:00
Ben Carman
721b28aefd Add listSpentAddresses call (#1406) 2020-05-12 07:24:52 -05:00
Chris Stewart
65f21acbf8 2020 05 11 bech32 addr tostring (#1413)
* Make Bech32Address.toString actually print the string representation not the object one

* Remove Bech32Address.toString all together and use the super class definition

* Add test case

* Run scalafmt
2020-05-11 10:59:36 -05:00
Nadav Kohen
a503441619 Crypto Project Refactor (#1380)
* Added crypto project and decoupled BitcoinSLogger from NetworkElement

Decoupled BitcoinSLogger from Factory

Moved NetworkElement into crypto project

Moved Factory and BitcoinSUtil (renamed to BytesUtil) to crypto project

Moved MaskedToString to crypto project

Added BytesUtil to imports and cleaned up CryptoUtil.recoverPoint

Moved the rest of crypto stuff to the crypto project

Moved crypto tests to crypto-test project

* Added documentation for crypto project
2020-04-30 12:34:53 -05:00
Ben Carman
6d7685b76e Add wallet creation time for rescans (#1353)
* Add wallet creation time for rescans

* Fix docs

* Clean up and add test

* Remove account bday

* Fix compile issue and docs

* Add more chain handler tests

* Use Instant over Long, add docs

* Fix docs
2020-04-29 09:49:41 -05:00
Ben Carman
b8331d4cf1 Re-enable NeutrinoNodeWithWalletTest for Linux (#1366)
* Re-enable NeutrinoNodeWithWalletTest with it disabled for mac

* Change to only Linux

* Only disable for CI runs

* Move IsCI to BitcoinSUtil

* Fix compile issue for earlier versions

* Fix syncing compact filters to not skip last filter

* Fix test to be compatible with new start state

* Use correct isCI

* Fix compile issue

* set CI env
2020-04-27 18:20:47 -05:00
Ben Carman
3f14add2d0 Ignore immature coinbase outputs when funding a transaction (#1365)
* Ignore immature coinbase outputs when funding a transaction

* Create Consensus.coinbaseMaturity
2020-04-24 18:04:42 -05:00
Ben Carman
dd479afae1 Fix isMinimalPush to not look for OP_1Negate when pushing 0x4f(79) (#1367) 2020-04-24 09:42:49 -05:00
Chris Stewart
cb88b78540 Bump scala version to 2.13.2 (#1360) 2020-04-23 07:38:20 -05:00
Ben Carman
39088475e3 Add sendrawtransaction CLI and Api commands 2020-04-21 13:14:02 -05:00
Nadav Kohen
ea4a5e0c42 Increased test coverage by 0.97% (#1343) 2020-04-20 12:53:51 -05:00
Ben Carman
00e4cf4c95 TransactionSignatureChecker bug fix and tests (#1341)
* TransactionSignatureChecker bug fix and tests

* Add new tests
2020-04-20 08:57:36 -05:00
Ben Carman
c696a7306b Require that addresses are the correct network when sending (#1332)
* Require that addresses are the correct network when sending

* Compare network bytes so typed addresses work

* Use isSameNetworkBytes
2020-04-13 13:58:41 -05:00
Ben Carman
b3250dcfba Update TxoState for transactions after they've been confirmed (#1178)
* Add onBlockHeadersReceived NodeCallback

* Add requiredConfirmations config option

* Update TxoState for transactions after they've been confirmed

* Response to review

* Fix compile issue
2020-04-08 16:51:17 -05:00
Nadav Kohen
ec0af42ce4 Removed SingleSigner abstraction and replaced with a simple signSingle method in SignerUtils (#1308) 2020-04-07 14:26:07 -05:00
Ben Carman
774e03a0f5 P2WSH Signer fix + tests (#1300)
* P2WSH Signer fix + tests

* Respond to review
2020-04-05 07:42:57 -05:00
Ben Carman
29eb6c2e05 Wallet Transaction Tracking (#1197)
* Incoming and Outgoing Transaction Tables

* Remove script sigs for witness txs

* Create parent tx_table for incoming and outgoing txs

* Response to review

* Use isCloseEnough

* Fix test

* Fix rebase error

* Test that tx is tracking all sats correctly
2020-04-02 06:55:09 -05:00
Chris Stewart
5eef801813 Fix hardcoded network for the default wallet account (#1277)
* Fix hardcoded network for the default wallet account

* Refactor call to HDUtil.getCoinType()
2020-03-30 12:30:48 -05:00
Chris Stewart
14b13eb612 2020 03 28 uint32 cache (#1279)
* Make it so we re-use cached values for UInt32, Int32 to try and reduce object allocations

* Run scalafmt

* Add named args

* Remove import
2020-03-30 12:29:34 -05:00
Chris Stewart
0d60e0f822 Replace all usages of List inside of ScriptParser with Vector (#1280) 2020-03-30 12:28:31 -05:00
Ben Carman
f6515c6779 Give ScriptInterpreter functions to verify a transaction or single input (#1223)
* Add TxSigCompenent constuctor

* Add verifyInputScript to ScriptInterpreter

* Add tests
2020-03-19 07:58:56 -05:00
Chris Stewart
44e4ab9a7e 2020 03 15 chainhandler getnancestor (#1247)
* Rename BlockHeaderDAO.getNChildren() to BlockHeaderDAO.getNAncestor() as that is what it actually does

* This changes the behavior of BlockHeaderDAO.getNAncestors from the previous implementation which just fetched headers in between two heights, to actually validating the headers that are fetched from the database with Blockchain.reconstructFromheaders()

* Run scalafmt

* Replace BlockHeader.getNAncestors call to Blockchain.reconstructFromHeaders() with Blockchain.connectWalkBackwards() so that we don't do full POW validation from the database, just make sure the headers connect to avoid reorg problems. Also add some more informative logs

* Address Roman's code review
2020-03-18 05:51:31 -05:00
Nadav Kohen
e0b234843d Bouncy Castle Fallback (#1232)
* Added Bouncy Castle fallback to all Secp calls in ECKey.scala

* Fixed bugs and made ExtKey support use of BouncyCastle

* An attempt to add bouncy castle testing to CI

* Responded to review

* De-coupled libsecp256k1 uses from Bouncy Castle uses

* Responded to review
2020-03-17 13:20:06 -05:00
Chris Stewart
3f5244e390 Fix missing pattern patch case for when we have zero headers (#1242) 2020-03-15 20:04:52 -05:00
Chris Stewart
cd84e3483d 2020 03 06 wallet rescan test (#1218)
* Add wallet rescan tests

* Create FilterSync, which gives us an API inside of the chain project to sync filters with

Add another unit test to filter sync

Add more unit tests for ChainSync and FilterSync

Clean up some docs, remove some extra lines of code

Run scalafmt

Add filter-sync.md

Cleanup some nits

Add more information of how FilterSync.syncFilters() works

Add 'FilterWithHeaderHash' type so that we can actually validate/verify block headers that are being fed into the chain project

Run scalafmt, hide imports in filter-sync.md so code appears cleaner

Move implicits out of invisible block as it seems to cause errors

Make it so FilterSync processes filters in batches rather than fetching them all at once

Fix compile error

* WIP bitcoind implement ChainQueryApi

* rework fixtures to be able to support injecting ChainQueryApi implemented by bitcoind into our fixture infrastructure for creating wallets

* Fix rebase problem

* Implement getFiltersBetweenHeight() with ben's solution

* WIP Start implementing NodeApi against bitcoind

* Actually inject the bitcoind backed nodeApi into our fixture

* Get first rescan test working for rescanning the entire blockchain

* Implement test case for rescanning from a specific height

* Fix NeutrinoNodeWalletTest test case that uses a experimental version of bitcoind, for now i believe our experimental binary is on v18

* Add wallet-rescan.md, add helper method to WalletApi that allows you to clear out the wallet's utxos/addresses

* Add another log to try to debug CI

* Address code review

* Fix wrong ordering of deletion of tables in clearUtxosAndAddresses()

* reset logging level
2020-03-13 16:11:02 -05:00
Chris Stewart
4c9a22f1e1 2020 03 08 filter sync (#1209)
* Create FilterSync, which gives us an API inside of the chain project to sync filters with

Add another unit test to filter sync

Add more unit tests for ChainSync and FilterSync

Clean up some docs, remove some extra lines of code

Run scalafmt

Add filter-sync.md

Cleanup some nits

Add more information of how FilterSync.syncFilters() works

Add 'FilterWithHeaderHash' type so that we can actually validate/verify block headers that are being fed into the chain project

Run scalafmt, hide imports in filter-sync.md so code appears cleaner

Move implicits out of invisible block as it seems to cause errors

Make it so FilterSync processes filters in batches rather than fetching them all at once

Fix compile error

* Add comment about trust model

* Run scalafmt
2020-03-10 18:01:14 -05:00
Nadav Kohen
052b64b7e2 Seq and Map Wrappers (#1131)
* Renamed size to byteSize in NetworkElement to avoid ambiguity

* Introduced SeqWrapper and MapWrapper to allow for wrapper case classes to have direct access to underlying methods

* Responded to review
2020-02-24 14:39:20 -06:00
Chris Stewart
7652105bdd Update dns seeds to reflect what is currently in bitcoin core, some of the old seeds do not exist anymore (#1157) 2020-02-22 12:24:59 -06:00
Ben Carman
cf3dd113b5 Reserved TxoState (#1111)
* Reserved TxoState

* Allow fund transaction handling to mark utxos as Reserved

* Add test, fix overloading default arg issue
2020-02-13 06:51:50 -06:00
Ben Carman
bc34e2d327 Descriptor fixes and test (#1116) 2020-02-13 06:48:15 -06:00
Ben Carman
964fcbc064 Replace null values with EmptyTransaction and PSBT.empty 2020-01-28 10:37:16 -06:00
Ben Carman
d2ed88067b CLI Commands for PSBTs 2020-01-28 00:06:15 -06:00