Pull over simple syntax changes for scala3 libraries (#5719)

* Pull over simple syntax changes for {cryptTest,coreTest,testkitCore,appCommons} from #5713

* Fix case analysis in Picklers.scala
This commit is contained in:
Chris Stewart 2024-10-17 13:00:33 -05:00 committed by GitHub
parent 90203b295b
commit ab6d3f5cb7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
41 changed files with 235 additions and 205 deletions

View File

@ -32,4 +32,4 @@ jobs:
~/.bitcoin-s/binaries ~/.bitcoin-s/binaries
key: ${{ runner.os }}-app-chain-core-tests-cache key: ${{ runner.os }}-app-chain-core-tests-cache
- name: run tests - name: run tests
run: sbt coverage dbCommonsTest/test chainTest/test chain/coverageReport chain/coverageAggregate chain/coveralls cryptoTestJVM/test cryptoJVM/test cryptoJVM/coverageReport cryptoJVM/coverageAggregate cryptoJVM/coveralls coreTestJVM/test coreJVM/coverageReport coreJVM/coverageAggregate coreJVM/coveralls secp256k1jni/test zmq/test zmq/coverageReport zmq/coverageAggregate zmq/coveralls appCommonsTest/test appServerTest/test oracleServerTest/test lnurlTest/test run: sbt -J-Xmx4g coverage dbCommonsTest/test chainTest/test chain/coverageReport chain/coverageAggregate chain/coveralls cryptoTestJVM/test cryptoJVM/test cryptoJVM/coverageReport cryptoJVM/coverageAggregate cryptoJVM/coveralls coreTestJVM/test coreJVM/coverageReport coreJVM/coverageAggregate coreJVM/coveralls secp256k1jni/test zmq/test zmq/coverageReport zmq/coverageAggregate zmq/coveralls appCommonsTest/test appServerTest/test oracleServerTest/test lnurlTest/test

View File

@ -30,4 +30,4 @@ jobs:
~/.bitcoin-s/binaries ~/.bitcoin-s/binaries
key: ${{ runner.os }}-keymanager-wallet-dlc-test-cache key: ${{ runner.os }}-keymanager-wallet-dlc-test-cache
- name: run tests - name: run tests
run: sbt coverage keyManagerTest/test keyManager/coverageReport keyManager/coverageAggregate keyManager/coveralls feeProviderTest/test walletTest/test dlcWalletTest/test wallet/coverageReport wallet/coverageAggregate wallet/coveralls dlcOracleTest/test asyncUtilsTestJVM/test dlcOracle/coverageReport dlcOracle/coverageAggregate dlcOracle/coveralls run: sbt -J-Xmx4g coverage keyManagerTest/test keyManager/coverageReport keyManager/coverageAggregate keyManager/coveralls feeProviderTest/test walletTest/test dlcWalletTest/test wallet/coverageReport wallet/coverageAggregate wallet/coveralls dlcOracleTest/test asyncUtilsTestJVM/test dlcOracle/coverageReport dlcOracle/coverageAggregate dlcOracle/coveralls

View File

@ -30,4 +30,4 @@ jobs:
~/.bitcoin-s/binaries ~/.bitcoin-s/binaries
key: ${{ runner.os }}-node-test-cache key: ${{ runner.os }}-node-test-cache
- name: run tests - name: run tests
run: sbt -J-Xmx2g cryptoTestJS/test coreJS/test 'set scalaJSStage in Global := FullOptStage' cryptoTestJS/test coreJS/test asyncUtilsTestJS/test coverage nodeTest/test node/coverageReport node/coverageAggregate node/coveralls dlcNodeTest/test run: sbt -J-Xmx4g cryptoTestJS/test coreJS/test 'set scalaJSStage in Global := FullOptStage' cryptoTestJS/test coreJS/test asyncUtilsTestJS/test coverage nodeTest/test node/coverageReport node/coverageAggregate node/coveralls dlcNodeTest/test

View File

@ -30,4 +30,4 @@ jobs:
~/.bitcoin-s/binaries ~/.bitcoin-s/binaries
key: ${{ runner.os }}-rpc-tests-cache key: ${{ runner.os }}-rpc-tests-cache
- name: run tests - name: run tests
run: sbt coverage bitcoindRpcTest/test bitcoindRpc/coverageReport bitcoindRpc/coverageAggregate bitcoindRpc/coveralls eclairRpcTest/test eclairRpc/coverageReport eclairRpc/coverageAggregate eclairRpc/coveralls lndRpcTest/test clightningRpcTest/test esploraTest/test run: sbt -J-Xmx4g coverage bitcoindRpcTest/test bitcoindRpc/coverageReport bitcoindRpc/coverageAggregate bitcoindRpc/coveralls eclairRpcTest/test eclairRpc/coverageReport eclairRpc/coverageAggregate eclairRpc/coveralls lndRpcTest/test clightningRpcTest/test esploraTest/test

View File

@ -32,4 +32,4 @@ jobs:
~/.bitcoin-s/binaries ~/.bitcoin-s/binaries
key: ${{ runner.os }}-wallet-node-dlc-test-cache key: ${{ runner.os }}-wallet-node-dlc-test-cache
- name: run tests - name: run tests
run: sbt coverage cryptoTestJVM/test coreTestJVM/test secp256k1jni/test zmq/test appCommonsTest/test asyncUtilsTestJVM/test chainTest/test dlcNodeTest/test appServerTest/test run: sbt -J-Xmx4g coverage cryptoTestJVM/test coreTestJVM/test secp256k1jni/test zmq/test appCommonsTest/test asyncUtilsTestJVM/test chainTest/test dlcNodeTest/test appServerTest/test

View File

@ -32,4 +32,4 @@ jobs:
~/.bitcoin-s/binaries ~/.bitcoin-s/binaries
key: ${{ runner.os }}-rpc-tests-cache key: ${{ runner.os }}-rpc-tests-cache
- name: run tests - name: run tests
run: sbt coverage bitcoindRpcTest/test bitcoindRpc/coverageReport bitcoindRpc/coverageAggregate bitcoindRpc/coveralls eclairRpcTest/test eclairRpc/coverageReport eclairRpc/coverageAggregate eclairRpc/coveralls lndRpcTest/test esploraTest/test run: sbt -J-Xmx4g coverage bitcoindRpcTest/test bitcoindRpc/coverageReport bitcoindRpc/coverageAggregate bitcoindRpc/coveralls eclairRpcTest/test eclairRpc/coverageReport eclairRpc/coverageAggregate eclairRpc/coveralls lndRpcTest/test esploraTest/test

View File

@ -32,4 +32,4 @@ jobs:
~/.bitcoin-s/binaries ~/.bitcoin-s/binaries
key: ${{ runner.os }}-wallet-node-dlc-test-cache key: ${{ runner.os }}-wallet-node-dlc-test-cache
- name: run tests - name: run tests
run: sbt coverage walletTest/test dlcWalletTest/test wallet/coverageReport wallet/coverageAggregate wallet/coveralls nodeTest/test node/coverageReport node/coverageAggregate node/coveralls dlcOracleTest/test dlcOracle/coverageReport dlcOracle/coveralls run: sbt -J-Xmx4g coverage walletTest/test dlcWalletTest/test wallet/coverageReport wallet/coverageAggregate wallet/coveralls nodeTest/test node/coverageReport node/coverageAggregate node/coveralls dlcOracleTest/test dlcOracle/coverageReport dlcOracle/coveralls

View File

@ -34,4 +34,4 @@ jobs:
~/.bitcoin-s/binaries ~/.bitcoin-s/binaries
key: ${{ runner.os }}-postgres-cache key: ${{ runner.os }}-postgres-cache
- name: run tests - name: run tests
run: sbt dbCommonsTest/test walletTest/test dlcWalletTest/test chainTest/test dlcOracleTest/test nodeTest/test run: sbt -J-Xmx4g dbCommonsTest/test walletTest/test dlcWalletTest/test chainTest/test dlcOracleTest/test nodeTest/test

View File

@ -35,5 +35,5 @@ jobs:
~/.bitcoin-s/binaries ~/.bitcoin-s/binaries
key: ${{ runner.os }}-cache key: ${{ runner.os }}-cache
- name: Windows Crypto, Core, and Database tests - name: Windows Crypto, Core, and Database tests
run: sbt cryptoTestJVM/test coreTestJVM/test secp256k1jni/test zmq/test appCommonsTest/test asyncUtilsTestJVM/test asyncUtilsTestJS/test appServerTest/test run: sbt -J-Xmx4g cryptoTestJVM/test coreTestJVM/test secp256k1jni/test zmq/test appCommonsTest/test asyncUtilsTestJVM/test asyncUtilsTestJS/test appServerTest/test
shell: bash shell: bash

View File

@ -25,4 +25,4 @@ jobs:
username: ${{ secrets.DOCKER_HUB_USERNAME }} username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Build and push - name: Build and push
run: sbt "oracleServer/docker:publish;appServer/docker:publish" run: sbt -J-Xmx4g "oracleServer/docker:publish;appServer/docker:publish"

View File

@ -36,7 +36,7 @@ jobs:
# from https://github.com/graalvm/graalvm-ce-builds/releases # from https://github.com/graalvm/graalvm-ce-builds/releases
java-version: graalvm@21.0.2=tgz+https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_${{runner.os}}-x64_bin.tar.gz java-version: graalvm@21.0.2=tgz+https://github.com/graalvm/graalvm-ce-builds/releases/download/jdk-21.0.2/graalvm-community-jdk-21.0.2_${{runner.os}}-x64_bin.tar.gz
- run: git fetch --tags || true - run: git fetch --tags || true
- run: sbt cli/nativeImage - run: sbt -J-Xmx4g cli/nativeImage
shell: bash shell: bash
if: ${{ matrix.os != 'windows-latest' }} if: ${{ matrix.os != 'windows-latest' }}
- run: echo $(pwd) - run: echo $(pwd)

View File

@ -21,7 +21,7 @@ jobs:
java-version: '21.0.4' java-version: '21.0.4'
cache: 'sbt' cache: 'sbt'
- uses: olafurpg/setup-gpg@v3 - uses: olafurpg/setup-gpg@v3
- run: sbt -J-Xmx2g ci-release docs/publishWebsite - run: sbt -J-Xmx4g ci-release docs/publishWebsite
env: env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }} PGP_SECRET: ${{ secrets.PGP_SECRET }}
@ -68,7 +68,7 @@ jobs:
run: brew install sbt run: brew install sbt
- name: Build all zips - name: Build all zips
shell: bash # windows needs shell defined shell: bash # windows needs shell defined
run: sbt "universal:stage;universal:packageBin" run: sbt -J-Xmx4g "universal:stage;universal:packageBin"
- name: View Artifacts - name: View Artifacts
run: ls -l app/server/target/universal/stage run: ls -l app/server/target/universal/stage
# - name: Build appServer # - name: Build appServer

View File

@ -51,7 +51,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
assert(read[DLCStatus](write(status)) == status) assert(read[DLCStatus](write(status)) == status)
assert( assert(
read[DLCStatus]( read[DLCStatus](
write(status.asInstanceOf[DLCStatus])(Picklers.dlcStatusW) write(status.asInstanceOf[DLCStatus])(using Picklers.dlcStatusW)
) == status ) == status
) )
} }
@ -100,7 +100,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
assert(read[DLCStatus](write(status)) == status) assert(read[DLCStatus](write(status)) == status)
assert( assert(
read[DLCStatus]( read[DLCStatus](
write(status.asInstanceOf[DLCStatus])(Picklers.dlcStatusW) write(status.asInstanceOf[DLCStatus])(using Picklers.dlcStatusW)
) == status ) == status
) )
} }
@ -142,7 +142,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
assert(read[DLCStatus](write(status)) == status) assert(read[DLCStatus](write(status)) == status)
assert( assert(
read[DLCStatus]( read[DLCStatus](
write(status.asInstanceOf[DLCStatus])(Picklers.dlcStatusW) write(status.asInstanceOf[DLCStatus])(using Picklers.dlcStatusW)
) == status ) == status
) )
} }
@ -184,7 +184,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
assert(read[DLCStatus](write(status)) == status) assert(read[DLCStatus](write(status)) == status)
assert( assert(
read[DLCStatus]( read[DLCStatus](
write(status.asInstanceOf[DLCStatus])(Picklers.dlcStatusW) write(status.asInstanceOf[DLCStatus])(using Picklers.dlcStatusW)
) == status ) == status
) )
} }
@ -226,7 +226,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
assert(read[DLCStatus](write(status)) == status) assert(read[DLCStatus](write(status)) == status)
assert( assert(
read[DLCStatus]( read[DLCStatus](
write(status.asInstanceOf[DLCStatus])(Picklers.dlcStatusW) write(status.asInstanceOf[DLCStatus])(using Picklers.dlcStatusW)
) == status ) == status
) )
} }
@ -283,7 +283,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
assert(read[DLCStatus](write(status)) == status) assert(read[DLCStatus](write(status)) == status)
assert( assert(
read[DLCStatus]( read[DLCStatus](
write(status.asInstanceOf[DLCStatus])(Picklers.dlcStatusW) write(status.asInstanceOf[DLCStatus])(using Picklers.dlcStatusW)
) == status ) == status
) )
} }
@ -342,7 +342,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
assert(read[DLCStatus](write(status)) == status) assert(read[DLCStatus](write(status)) == status)
assert( assert(
read[DLCStatus]( read[DLCStatus](
write(status.asInstanceOf[DLCStatus])(Picklers.dlcStatusW) write(status.asInstanceOf[DLCStatus])(using Picklers.dlcStatusW)
) == status ) == status
) )
} }
@ -395,7 +395,7 @@ class DLCStatusTest extends BitcoinSJvmTest {
assert(read[DLCStatus](write(status)) == status) assert(read[DLCStatus](write(status)) == status)
assert( assert(
read[DLCStatus]( read[DLCStatus](
write(status.asInstanceOf[DLCStatus])(Picklers.dlcStatusW) write(status.asInstanceOf[DLCStatus])(using Picklers.dlcStatusW)
) == status ) == status
) )
} }

View File

@ -51,10 +51,10 @@ class DLCAcceptJsonSerializerTest extends BitcoinSUnitTest {
it must "have serialization symmetry for a accept json message" in { it must "have serialization symmetry for a accept json message" in {
val accept = upickle.default.read[DLCAcceptTLV](testString)( val accept = upickle.default.read[DLCAcceptTLV](testString)(
Picklers.dlcAcceptTLVPickler using Picklers.dlcAcceptTLVPickler
) )
val json: String = val json: String =
upickle.default.write(accept)(Picklers.dlcAcceptTLVPickler) upickle.default.write(accept)(using Picklers.dlcAcceptTLVPickler)
assert(json == testString.replaceAll("\\s", "")) assert(json == testString.replaceAll("\\s", ""))
} }

View File

@ -48,9 +48,10 @@ class DLCSignJsonSerializerTest extends BitcoinSUnitTest {
it must "have serialization symmetry for dlc sign messages" in { it must "have serialization symmetry for dlc sign messages" in {
val sign = val sign =
upickle.default.read[DLCSignTLV](testString)(Picklers.dlcSignTLVPickler) upickle.default.read[DLCSignTLV](testString)(
using Picklers.dlcSignTLVPickler)
val json: String = val json: String =
upickle.default.write(sign)(Picklers.dlcSignTLVPickler) upickle.default.write(sign)(using Picklers.dlcSignTLVPickler)
assert(json == testString.replaceAll("\\s", "")) assert(json == testString.replaceAll("\\s", ""))
} }
} }

View File

@ -11,10 +11,11 @@ class SpendingInfoDbSerializerTest extends BitcoinSUnitTest {
it must "be symmetrical" in { it must "be symmetrical" in {
val original = TransactionTestUtil.spendingInfoDb val original = TransactionTestUtil.spendingInfoDb
val json = upickle.default.writeJs[SpendingInfoDb](original)( val json = upickle.default.writeJs[SpendingInfoDb](original)(
Picklers.spendingInfoDbPickler using Picklers.spendingInfoDbPickler
) )
val parsed = upickle.default.read(json)(Picklers.spendingInfoDbPickler) val parsed =
upickle.default.read(json)(using Picklers.spendingInfoDbPickler)
assert(parsed == original) assert(parsed == original)
} }

View File

@ -23,14 +23,15 @@ object ContractDescriptorParser {
value match { value match {
case obj: Obj => case obj: Obj =>
upickle.default upickle.default
.read[ContractDescriptorV0TLV](obj)(Picklers.contractDescriptorV0) .read[ContractDescriptorV0TLV](obj)(
using Picklers.contractDescriptorV0)
case arr: Arr => case arr: Arr =>
// we read the number of digits from the announcement, // we read the number of digits from the announcement,
// take in tlv points for the payout curve // take in tlv points for the payout curve
// and don't provide access to give a rounding mode as a parameter // and don't provide access to give a rounding mode as a parameter
val payoutPoints: Vector[TLVPoint] = arr.value.toVector.map { pointJs => val payoutPoints: Vector[TLVPoint] = arr.value.toVector.map { pointJs =>
upickle.default upickle.default
.read[TLVPoint](pointJs)(Picklers.tlvPointReader) .read[TLVPoint](pointJs)(using Picklers.tlvPointReader)
} }
val payoutCurve = DLCPayoutCurve val payoutCurve = DLCPayoutCurve

View File

@ -178,7 +178,7 @@ object WalletNotification {
override val `type`: WalletWsType = WalletWsType.NewAddress override val `type`: WalletWsType = WalletWsType.NewAddress
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.newAddressPickler) upickle.default.writeJs(this)(using WsPicklers.newAddressPickler)
} }
} }
@ -187,7 +187,7 @@ object WalletNotification {
override val `type`: WalletWsType = WalletWsType.TxProcessed override val `type`: WalletWsType = WalletWsType.TxProcessed
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.txProcessedPickler) upickle.default.writeJs(this)(using WsPicklers.txProcessedPickler)
} }
} }
@ -196,7 +196,7 @@ object WalletNotification {
override val `type`: WalletWsType = WalletWsType.TxBroadcast override val `type`: WalletWsType = WalletWsType.TxBroadcast
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.txBroadcastPickler) upickle.default.writeJs(this)(using WsPicklers.txBroadcastPickler)
} }
} }
@ -205,7 +205,7 @@ object WalletNotification {
override val `type`: WalletWsType = WalletWsType.ReservedUtxos override val `type`: WalletWsType = WalletWsType.ReservedUtxos
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.reservedUtxosPickler) upickle.default.writeJs(this)(using WsPicklers.reservedUtxosPickler)
} }
} }
@ -214,7 +214,7 @@ object WalletNotification {
override val `type`: WalletWsType = WalletWsType.DLCStateChange override val `type`: WalletWsType = WalletWsType.DLCStateChange
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.dlcStateChangePickler) upickle.default.writeJs(this)(using WsPicklers.dlcStateChangePickler)
} }
} }
@ -223,7 +223,7 @@ object WalletNotification {
override val `type`: WalletWsType = WalletWsType.DLCOfferAdd override val `type`: WalletWsType = WalletWsType.DLCOfferAdd
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.dlcOfferAddPickler) upickle.default.writeJs(this)(using WsPicklers.dlcOfferAddPickler)
} }
} }
@ -232,7 +232,7 @@ object WalletNotification {
override val `type`: WalletWsType = WalletWsType.DLCOfferRemove override val `type`: WalletWsType = WalletWsType.DLCOfferRemove
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.dlcOfferRemovePickler) upickle.default.writeJs(this)(using WsPicklers.dlcOfferRemovePickler)
} }
} }
@ -241,7 +241,7 @@ object WalletNotification {
override val `type`: WalletWsType = WalletWsType.RescanComplete override val `type`: WalletWsType = WalletWsType.RescanComplete
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.rescanPickler) upickle.default.writeJs(this)(using WsPicklers.rescanPickler)
} }
} }
@ -250,7 +250,7 @@ object WalletNotification {
override val `type`: WalletWsType = WalletWsType.FeeRateChange override val `type`: WalletWsType = WalletWsType.FeeRateChange
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.feeRatePickler) upickle.default.writeJs(this)(using WsPicklers.feeRatePickler)
} }
} }
} }
@ -262,7 +262,7 @@ object ChainNotification {
override val `type`: ChainWsType = ChainWsType.BlockProcessed override val `type`: ChainWsType = ChainWsType.BlockProcessed
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.blockProcessedPickler) upickle.default.writeJs(this)(using WsPicklers.blockProcessedPickler)
} }
} }
@ -273,7 +273,7 @@ object ChainNotification {
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)( upickle.default.writeJs(this)(
WsPicklers.compactFilterHeaderProcessedPickler using WsPicklers.compactFilterHeaderProcessedPickler
) )
} }
} }
@ -283,7 +283,8 @@ object ChainNotification {
override val `type`: ChainWsType = ChainWsType.CompactFilterProcessed override val `type`: ChainWsType = ChainWsType.CompactFilterProcessed
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.compactFilterProcessedPickler) upickle.default.writeJs(this)(
using WsPicklers.compactFilterProcessedPickler)
} }
} }
@ -292,7 +293,7 @@ object ChainNotification {
override val `type`: ChainWsType = ChainWsType.SyncFlagChanged override val `type`: ChainWsType = ChainWsType.SyncFlagChanged
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.syncFlagChangedPickler) upickle.default.writeJs(this)(using WsPicklers.syncFlagChangedPickler)
} }
} }
} }
@ -304,7 +305,7 @@ object TorNotification {
override val payload: Unit = () override val payload: Unit = ()
override val json: ujson.Value = { override val json: ujson.Value = {
upickle.default.writeJs(this)(WsPicklers.torStartedPickler) upickle.default.writeJs(this)(using WsPicklers.torStartedPickler)
} }
} }
} }
@ -316,7 +317,7 @@ object DLCNodeNotification {
override def `type`: DLCNodeWsType = DLCNodeWsType.DLCConnectionInitiated override def `type`: DLCNodeWsType = DLCNodeWsType.DLCConnectionInitiated
override def json: Value = upickle.default.writeJs(this)( override def json: Value = upickle.default.writeJs(this)(
WsPicklers.dlcNodeConnectionInitiatedPickler using WsPicklers.dlcNodeConnectionInitiatedPickler
) )
} }
@ -325,7 +326,7 @@ object DLCNodeNotification {
override def `type`: DLCNodeWsType = DLCNodeWsType.DLCConnectionEstablished override def `type`: DLCNodeWsType = DLCNodeWsType.DLCConnectionEstablished
override def json: Value = upickle.default.writeJs(this)( override def json: Value = upickle.default.writeJs(this)(
WsPicklers.dlcNodeConnectionEstablishedPickler using WsPicklers.dlcNodeConnectionEstablishedPickler
) )
} }
@ -334,7 +335,8 @@ object DLCNodeNotification {
override def `type`: DLCNodeWsType = DLCNodeWsType.DLCConnectionFailed override def `type`: DLCNodeWsType = DLCNodeWsType.DLCConnectionFailed
override def json: Value = override def json: Value =
upickle.default.writeJs(this)(WsPicklers.dlcNodeConnectionFailedPickler) upickle.default.writeJs(this)(
using WsPicklers.dlcNodeConnectionFailedPickler)
} }
case class DLCAcceptFailed(payload: (Sha256Digest, String)) case class DLCAcceptFailed(payload: (Sha256Digest, String))
@ -342,7 +344,7 @@ object DLCNodeNotification {
override def `type`: DLCNodeWsType = DLCNodeWsType.DLCAcceptFailed override def `type`: DLCNodeWsType = DLCNodeWsType.DLCAcceptFailed
override def json: Value = override def json: Value =
upickle.default.writeJs(this)(WsPicklers.dlcAcceptFailedPickler) upickle.default.writeJs(this)(using WsPicklers.dlcAcceptFailedPickler)
} }
case class DLCAcceptSucceed(payload: Sha256Digest) case class DLCAcceptSucceed(payload: Sha256Digest)
@ -350,7 +352,7 @@ object DLCNodeNotification {
override def `type`: DLCNodeWsType = DLCNodeWsType.DLCAcceptSucceed override def `type`: DLCNodeWsType = DLCNodeWsType.DLCAcceptSucceed
override def json: Value = override def json: Value =
upickle.default.writeJs(this)(WsPicklers.dlcAcceptSucceedPickler) upickle.default.writeJs(this)(using WsPicklers.dlcAcceptSucceedPickler)
} }
case class DLCOfferSendFailed(payload: (Sha256Digest, String)) case class DLCOfferSendFailed(payload: (Sha256Digest, String))
@ -358,7 +360,7 @@ object DLCNodeNotification {
override def `type`: DLCNodeWsType = DLCNodeWsType.DLCOfferSendFailed override def `type`: DLCNodeWsType = DLCNodeWsType.DLCOfferSendFailed
override def json: Value = override def json: Value =
upickle.default.writeJs(this)(WsPicklers.dlcOfferSendFailedPickler) upickle.default.writeJs(this)(using WsPicklers.dlcOfferSendFailedPickler)
} }
case class DLCOfferSendSucceed(payload: Sha256Digest) case class DLCOfferSendSucceed(payload: Sha256Digest)
@ -366,7 +368,7 @@ object DLCNodeNotification {
override def `type`: DLCNodeWsType = DLCNodeWsType.DLCOfferSendSucceed override def `type`: DLCNodeWsType = DLCNodeWsType.DLCOfferSendSucceed
override def json: Value = override def json: Value =
upickle.default.writeJs(this)(WsPicklers.dlcOfferSendSucceedPickler) upickle.default.writeJs(this)(using WsPicklers.dlcOfferSendSucceedPickler)
} }
case class DLCSignFailed(payload: (Sha256Digest, String)) case class DLCSignFailed(payload: (Sha256Digest, String))
@ -374,7 +376,7 @@ object DLCNodeNotification {
override def `type`: DLCNodeWsType = DLCNodeWsType.DLCSignFailed override def `type`: DLCNodeWsType = DLCNodeWsType.DLCSignFailed
override def json: Value = override def json: Value =
upickle.default.writeJs(this)(WsPicklers.dlcSignFailedPickler) upickle.default.writeJs(this)(using WsPicklers.dlcSignFailedPickler)
} }
case class DLCSignSucceed(payload: Sha256Digest) case class DLCSignSucceed(payload: Sha256Digest)
@ -382,6 +384,6 @@ object DLCNodeNotification {
override def `type`: DLCNodeWsType = DLCNodeWsType.DLCSignSucceed override def `type`: DLCNodeWsType = DLCNodeWsType.DLCSignSucceed
override def json: Value = override def json: Value =
upickle.default.writeJs(this)(WsPicklers.dlcSignSucceedPickler) upickle.default.writeJs(this)(using WsPicklers.dlcSignSucceedPickler)
} }
} }

View File

@ -1812,7 +1812,7 @@ object CreateNewAccount {
def fromJsArr(arr: ujson.Arr): Try[CreateNewAccount] = { def fromJsArr(arr: ujson.Arr): Try[CreateNewAccount] = {
arr.arr.toVector match { arr.arr.toVector match {
case purposeJs +: _ => case purposeJs +: _ =>
Try(upickle.default.read(purposeJs)(Picklers.hdPurpose)) Try(upickle.default.read(purposeJs)(using Picklers.hdPurpose))
.map(CreateNewAccount.apply) .map(CreateNewAccount.apply)
case _ => case _ =>
val exn = new IllegalArgumentException( val exn = new IllegalArgumentException(

View File

@ -558,7 +558,7 @@ object Picklers {
// can't make implicit because it will overlap with ones needed for cli // can't make implicit because it will overlap with ones needed for cli
val oracleAnnouncementTLVJsonWriter: Writer[OracleAnnouncementTLV] = val oracleAnnouncementTLVJsonWriter: Writer[OracleAnnouncementTLV] =
writer[Value].comap { case v0: OracleAnnouncementV0TLV => writer[Value].comap { case v0: OracleAnnouncementV0TLV =>
writeJs(v0)(announcementV0JsonWriter) writeJs(v0)(using announcementV0JsonWriter)
} }
// can't make implicit because it will overlap with ones needed for cli // can't make implicit because it will overlap with ones needed for cli
@ -577,7 +577,7 @@ object Picklers {
implicit val fundingInputV0Writer: Writer[FundingInputTLV] = implicit val fundingInputV0Writer: Writer[FundingInputTLV] =
writer[Value].comap { case v0: FundingInputV0TLV => writer[Value].comap { case v0: FundingInputV0TLV =>
writeJs(v0)(fundingInputWriter) writeJs(v0)(using fundingInputWriter)
} }
implicit val fundingInputWriter: Writer[FundingInputV0TLV] = implicit val fundingInputWriter: Writer[FundingInputV0TLV] =
@ -730,16 +730,16 @@ object Picklers {
implicit val contractDescriptorWriter: Writer[ContractDescriptorTLV] = implicit val contractDescriptorWriter: Writer[ContractDescriptorTLV] =
writer[Value].comap { writer[Value].comap {
case v0: ContractDescriptorV0TLV => case v0: ContractDescriptorV0TLV =>
writeJs(v0)(contractDescriptorV0) writeJs(v0)(using contractDescriptorV0)
case v1: ContractDescriptorV1TLV => case v1: ContractDescriptorV1TLV =>
writeJs(v1)(contractDescriptorV1Writer) writeJs(v1)(using contractDescriptorV1Writer)
} }
implicit val oracleInfoV0TLVWriter: Writer[OracleInfoV0TLV] = implicit val oracleInfoV0TLVWriter: Writer[OracleInfoV0TLV] =
writer[Obj].comap { oracleInfo => writer[Obj].comap { oracleInfo =>
Obj( Obj(
"announcement" -> writeJs(oracleInfo.announcement)( "announcement" -> writeJs(oracleInfo.announcement)(
oracleAnnouncementTLVJsonWriter using oracleAnnouncementTLVJsonWriter
) )
) )
} }
@ -750,7 +750,7 @@ object Picklers {
Obj( Obj(
"threshold" -> Num(threshold.toDouble), "threshold" -> Num(threshold.toDouble),
"announcements" -> oracles.map(o => "announcements" -> oracles.map(o =>
writeJs(o)(oracleAnnouncementTLVJsonWriter)) writeJs(o)(using oracleAnnouncementTLVJsonWriter))
) )
} }
@ -775,7 +775,7 @@ object Picklers {
Obj( Obj(
"threshold" -> Num(threshold.toDouble), "threshold" -> Num(threshold.toDouble),
"announcements" -> oracles.map(o => "announcements" -> oracles.map(o =>
writeJs(o)(oracleAnnouncementTLVJsonWriter)), writeJs(o)(using oracleAnnouncementTLVJsonWriter)),
"params" -> writeJs(params) "params" -> writeJs(params)
) )
} }
@ -825,9 +825,9 @@ object Picklers {
val contractInfoJsonWriter: Writer[ContractInfoTLV] = { val contractInfoJsonWriter: Writer[ContractInfoTLV] = {
writer[ujson.Value].comap { writer[ujson.Value].comap {
case contractInfoV0TLV: ContractInfoV0TLV => case contractInfoV0TLV: ContractInfoV0TLV =>
writeJs(contractInfoV0TLV)(contractInfoV0TLVJsonWriter) writeJs(contractInfoV0TLV)(using contractInfoV0TLVJsonWriter)
case contractInfoV1TLV: ContractInfoV1TLV => case contractInfoV1TLV: ContractInfoV1TLV =>
writeJs(contractInfoV1TLV)(contractInfoV1TLVJsonWriter) writeJs(contractInfoV1TLV)(using contractInfoV1TLVJsonWriter)
} }
} }
@ -835,9 +835,9 @@ object Picklers {
writer[Obj].comap { offer => writer[Obj].comap { offer =>
import offer._ import offer._
Obj( Obj(
"contractFlags" -> Str(contractFlags.toHexString), "contractFlags" -> Str(ByteVector.fromByte(contractFlags).toHex),
"chainHash" -> Str(chainHash.hex), "chainHash" -> Str(chainHash.hex),
"contractInfo" -> writeJs(contractInfo)(contractInfoJsonWriter), "contractInfo" -> writeJs(contractInfo)(using contractInfoJsonWriter),
"fundingPubKey" -> Str(fundingPubKey.hex), "fundingPubKey" -> Str(fundingPubKey.hex),
"payoutSPK" -> Str(payoutSPK.hex), "payoutSPK" -> Str(payoutSPK.hex),
"payoutSerialId" -> Num(payoutSerialId.toBigInt.toDouble), "payoutSerialId" -> Num(payoutSerialId.toBigInt.toDouble),
@ -1211,25 +1211,25 @@ object Picklers {
implicit val dlcStatusW: Writer[DLCStatus] = writer[Value].comap { implicit val dlcStatusW: Writer[DLCStatus] = writer[Value].comap {
case o: Offered => case o: Offered =>
writeJs(o)(offeredW) writeJs(o)(using offeredW)
case a: AcceptedComputingAdaptorSigs => case a: AcceptedComputingAdaptorSigs =>
writeJs(a)(acceptedComputingAdaptorSigsW) writeJs(a)(using acceptedComputingAdaptorSigsW)
case a: Accepted => case a: Accepted =>
writeJs(a)(acceptedW) writeJs(a)(using acceptedW)
case s: SignedComputingAdaptorSigs => case s: SignedComputingAdaptorSigs =>
writeJs(s)(signedComputingAdaptorSigsW) writeJs(s)(using signedComputingAdaptorSigsW)
case s: Signed => case s: Signed =>
writeJs(s)(signedW) writeJs(s)(using signedW)
case b: Broadcasted => case b: Broadcasted =>
writeJs(b)(broadcastedW) writeJs(b)(using broadcastedW)
case c: Confirmed => case c: Confirmed =>
writeJs(c)(confirmedW) writeJs(c)(using confirmedW)
case c: Claimed => case c: Claimed =>
writeJs(c)(claimedW) writeJs(c)(using claimedW)
case r: RemoteClaimed => case r: RemoteClaimed =>
writeJs(r)(remoteClaimedW) writeJs(r)(using remoteClaimedW)
case r: Refunded => case r: Refunded =>
writeJs(r)(refundedW) writeJs(r)(using refundedW)
} }
implicit val dlcOfferAddR: Reader[IncomingDLCOfferDb] = reader[Obj].map { implicit val dlcOfferAddR: Reader[IncomingDLCOfferDb] = reader[Obj].map {

View File

@ -69,17 +69,18 @@ object WsPicklers {
} }
private def writeChainNotification( private def writeChainNotification(
notification: ChainNotification[_] notification: ChainNotification[?]
): ujson.Obj = { ): ujson.Obj = {
val payloadJson: ujson.Value = notification match { val payloadJson: ujson.Value = notification match {
case BlockProcessedNotification(block) => case BlockProcessedNotification(block) =>
upickle.default.writeJs(block)(Picklers.getBlockHeaderResultPickler) upickle.default.writeJs(block)(
using Picklers.getBlockHeaderResultPickler)
case CompactFilterHeaderProcessedNotification(filterHeader) => case CompactFilterHeaderProcessedNotification(filterHeader) =>
upickle.default.writeJs(filterHeader)( upickle.default.writeJs(filterHeader)(
Picklers.compactFilterHeaderPickler using Picklers.compactFilterHeaderPickler
) )
case CompactFilterProcessedNotification(filter) => case CompactFilterProcessedNotification(filter) =>
upickle.default.writeJs(filter)(Picklers.compactFilterDbPickler) upickle.default.writeJs(filter)(using Picklers.compactFilterDbPickler)
case SyncFlagChangedNotification(syncing) => case SyncFlagChangedNotification(syncing) =>
upickle.default.writeJs(syncing) upickle.default.writeJs(syncing)
} }
@ -91,24 +92,27 @@ object WsPicklers {
notificationObj notificationObj
} }
private def readChainNotification(obj: ujson.Obj): ChainNotification[_] = { private def readChainNotification(obj: ujson.Obj): ChainNotification[?] = {
val typeObj = read[ChainWsType](obj(PicklerKeys.typeKey)) val typeObj = read[ChainWsType](obj(PicklerKeys.typeKey))
val payloadObj = obj(PicklerKeys.payloadKey) val payloadObj = obj(PicklerKeys.payloadKey)
typeObj match { typeObj match {
case ChainWsType.BlockProcessed => case ChainWsType.BlockProcessed =>
val block = val block =
upickle.default.read(payloadObj)(Picklers.getBlockHeaderResultPickler) upickle.default.read(payloadObj)(
using Picklers.getBlockHeaderResultPickler)
BlockProcessedNotification(block) BlockProcessedNotification(block)
case ChainWsType.CompactFilterHeaderProcessed => case ChainWsType.CompactFilterHeaderProcessed =>
val filterheader = val filterheader =
upickle.default.read(payloadObj)(Picklers.compactFilterHeaderPickler) upickle.default.read(payloadObj)(
using Picklers.compactFilterHeaderPickler)
CompactFilterHeaderProcessedNotification(filterheader) CompactFilterHeaderProcessedNotification(filterheader)
case ChainWsType.CompactFilterProcessed => case ChainWsType.CompactFilterProcessed =>
val filter = val filter =
upickle.default.read(payloadObj)(Picklers.compactFilterDbPickler) upickle.default.read(payloadObj)(
using Picklers.compactFilterDbPickler)
CompactFilterProcessedNotification(filter) CompactFilterProcessedNotification(filter)
case ChainWsType.SyncFlagChanged => case ChainWsType.SyncFlagChanged =>
val syncing = payloadObj.bool val syncing = payloadObj.bool
@ -117,29 +121,29 @@ object WsPicklers {
} }
private def writeWalletNotification( private def writeWalletNotification(
notification: WalletNotification[_] notification: WalletNotification[?]
): ujson.Obj = { ): ujson.Obj = {
val payloadJson: ujson.Value = notification match { val payloadJson: ujson.Value = notification match {
case TxBroadcastNotification(tx) => case TxBroadcastNotification(tx) =>
upickle.default.writeJs(tx)(Picklers.transactionPickler) upickle.default.writeJs(tx)(using Picklers.transactionPickler)
case TxProcessedNotification(tx) => case TxProcessedNotification(tx) =>
upickle.default.writeJs(tx)(Picklers.transactionPickler) upickle.default.writeJs(tx)(using Picklers.transactionPickler)
case NewAddressNotification(address) => case NewAddressNotification(address) =>
upickle.default.writeJs(address)(Picklers.bitcoinAddressPickler) upickle.default.writeJs(address)(using Picklers.bitcoinAddressPickler)
case ReservedUtxosNotification(utxos) => case ReservedUtxosNotification(utxos) =>
val vec = utxos.map(u => val vec = utxos.map(u =>
upickle.default.writeJs(u)(Picklers.spendingInfoDbPickler)) upickle.default.writeJs(u)(using Picklers.spendingInfoDbPickler))
ujson.Arr.from(vec) ujson.Arr.from(vec)
case DLCStateChangeNotification(status) => case DLCStateChangeNotification(status) =>
upickle.default.writeJs(status)(Picklers.dlcStatusW) upickle.default.writeJs(status)(using Picklers.dlcStatusW)
case DLCOfferAddNotification(offerDb) => case DLCOfferAddNotification(offerDb) =>
upickle.default.writeJs(offerDb)(Picklers.dlcOfferAddW) upickle.default.writeJs(offerDb)(using Picklers.dlcOfferAddW)
case DLCOfferRemoveNotification(offerHash) => case DLCOfferRemoveNotification(offerHash) =>
upickle.default.writeJs(offerHash)(Picklers.dlcOfferRemoveW) upickle.default.writeJs(offerHash)(using Picklers.dlcOfferRemoveW)
case r: RescanComplete => case r: RescanComplete =>
upickle.default.writeJs(r)(Picklers.rescanComplete) upickle.default.writeJs(r)(using Picklers.rescanComplete)
case FeeRateChange(feeRate) => case FeeRateChange(feeRate) =>
upickle.default.writeJs(feeRate)(Picklers.feeUnit) upickle.default.writeJs(feeRate)(using Picklers.feeUnit)
} }
val notificationObj = ujson.Obj( val notificationObj = ujson.Obj(
@ -149,45 +153,49 @@ object WsPicklers {
notificationObj notificationObj
} }
private def readWalletNotification(obj: ujson.Obj): WalletNotification[_] = { private def readWalletNotification(obj: ujson.Obj): WalletNotification[?] = {
val typeObj = read[WalletWsType](obj(PicklerKeys.typeKey)) val typeObj = read[WalletWsType](obj(PicklerKeys.typeKey))
val payloadObj = obj(PicklerKeys.payloadKey) val payloadObj = obj(PicklerKeys.payloadKey)
typeObj match { typeObj match {
case WalletWsType.TxBroadcast => case WalletWsType.TxBroadcast =>
val tx = upickle.default.read(payloadObj)(Picklers.transactionPickler) val tx =
upickle.default.read(payloadObj)(using Picklers.transactionPickler)
TxBroadcastNotification(tx) TxBroadcastNotification(tx)
case WalletWsType.TxProcessed => case WalletWsType.TxProcessed =>
val tx = upickle.default.read(payloadObj)(Picklers.transactionPickler) val tx =
upickle.default.read(payloadObj)(using Picklers.transactionPickler)
TxProcessedNotification(tx) TxProcessedNotification(tx)
case WalletWsType.NewAddress => case WalletWsType.NewAddress =>
val address = val address =
upickle.default.read(payloadObj)(Picklers.bitcoinAddressPickler) upickle.default.read(payloadObj)(using Picklers.bitcoinAddressPickler)
NewAddressNotification(address) NewAddressNotification(address)
case WalletWsType.ReservedUtxos => case WalletWsType.ReservedUtxos =>
val utxos = obj(PicklerKeys.payloadKey).arr.toVector.map { utxoJson => val utxos = obj(PicklerKeys.payloadKey).arr.toVector.map { utxoJson =>
upickle.default.read(utxoJson)(Picklers.spendingInfoDbPickler) upickle.default.read(utxoJson)(using Picklers.spendingInfoDbPickler)
} }
ReservedUtxosNotification(utxos) ReservedUtxosNotification(utxos)
case WalletWsType.DLCStateChange => case WalletWsType.DLCStateChange =>
val status = upickle.default.read(payloadObj)(Picklers.dlcStatusR) val status = upickle.default.read(payloadObj)(using Picklers.dlcStatusR)
DLCStateChangeNotification(status) DLCStateChangeNotification(status)
case WalletWsType.DLCOfferAdd => case WalletWsType.DLCOfferAdd =>
val offerDb = upickle.default.read(payloadObj)(Picklers.dlcOfferAddR) val offerDb =
upickle.default.read(payloadObj)(using Picklers.dlcOfferAddR)
DLCOfferAddNotification(offerDb) DLCOfferAddNotification(offerDb)
case WalletWsType.DLCOfferRemove => case WalletWsType.DLCOfferRemove =>
val offerHash = val offerHash =
upickle.default.read(payloadObj)(Picklers.dlcOfferRemoveR) upickle.default.read(payloadObj)(using Picklers.dlcOfferRemoveR)
DLCOfferRemoveNotification(offerHash) DLCOfferRemoveNotification(offerHash)
case WalletWsType.RescanComplete => case WalletWsType.RescanComplete =>
val complete = upickle.default.read(payloadObj)(Picklers.rescanComplete) val complete =
upickle.default.read(payloadObj)(using Picklers.rescanComplete)
complete complete
case WalletWsType.FeeRateChange => case WalletWsType.FeeRateChange =>
FeeRateChange(upickle.default.read(payloadObj)(Picklers.feeUnit)) FeeRateChange(upickle.default.read(payloadObj)(using Picklers.feeUnit))
} }
} }
private def writeTorNotification( private def writeTorNotification(
notification: TorNotification[_] notification: TorNotification[?]
): ujson.Obj = { ): ujson.Obj = {
val payloadJson = notification.`type` match { val payloadJson = notification.`type` match {
case TorWsType.TorStarted => case TorWsType.TorStarted =>
@ -201,7 +209,7 @@ object WsPicklers {
notificationObj notificationObj
} }
private def readTorNotification(obj: ujson.Obj): TorNotification[_] = { private def readTorNotification(obj: ujson.Obj): TorNotification[?] = {
val typeObj = read[TorWsType](obj(PicklerKeys.typeKey)) val typeObj = read[TorWsType](obj(PicklerKeys.typeKey))
typeObj match { typeObj match {
case TorWsType.TorStarted => case TorWsType.TorStarted =>
@ -210,7 +218,7 @@ object WsPicklers {
} }
private def writeDLCNodeNotification( private def writeDLCNodeNotification(
notification: DLCNodeNotification[_] notification: DLCNodeNotification[?]
): ujson.Obj = { ): ujson.Obj = {
def addr2str(address: InetSocketAddress) = def addr2str(address: InetSocketAddress) =
address.getHostName + ":" + address.getPort address.getHostName + ":" + address.getPort
@ -246,7 +254,7 @@ object WsPicklers {
private def readDLCNodeNotification( private def readDLCNodeNotification(
obj: ujson.Obj obj: ujson.Obj
): DLCNodeNotification[_] = { ): DLCNodeNotification[?] = {
val typeObj = read[DLCNodeWsType](obj(PicklerKeys.typeKey)) val typeObj = read[DLCNodeWsType](obj(PicklerKeys.typeKey))
val payloadObj = obj(PicklerKeys.payloadKey) val payloadObj = obj(PicklerKeys.payloadKey)
@ -328,16 +336,16 @@ object WsPicklers {
} }
implicit val dlcNodeNotificationPickler implicit val dlcNodeNotificationPickler
: ReadWriter[DLCNodeNotification[_]] = { : ReadWriter[DLCNodeNotification[?]] = {
readwriter[ujson.Obj] readwriter[ujson.Obj]
.bimap(writeDLCNodeNotification, readDLCNodeNotification) .bimap(writeDLCNodeNotification, readDLCNodeNotification)
} }
implicit val walletNotificationPickler: ReadWriter[WalletNotification[_]] = { implicit val walletNotificationPickler: ReadWriter[WalletNotification[?]] = {
readwriter[ujson.Obj].bimap(writeWalletNotification, readWalletNotification) readwriter[ujson.Obj].bimap(writeWalletNotification, readWalletNotification)
} }
implicit val chainNotificationPickler: ReadWriter[ChainNotification[_]] = { implicit val chainNotificationPickler: ReadWriter[ChainNotification[?]] = {
readwriter[ujson.Obj].bimap(writeChainNotification, readChainNotification) readwriter[ujson.Obj].bimap(writeChainNotification, readChainNotification)
} }

View File

@ -10,7 +10,7 @@ import scala.sys.process.{Process, ProcessBuilder, ProcessLogger}
trait NativeProcessFactory extends BitcoinSLogger { trait NativeProcessFactory extends BitcoinSLogger {
implicit protected def executionContext: ExecutionContext implicit protected def executionContext: ExecutionContext
private[this] var processOpt: Option[Process] = None private var processOpt: Option[Process] = None
private lazy val process: ProcessBuilder = scala.sys.process.Process(cmd) private lazy val process: ProcessBuilder = scala.sys.process.Process(cmd)

View File

@ -18,7 +18,7 @@ class TaprootWalletTestVectors extends BitcoinSUnitTest {
lazy val testCase: TaprootWalletTestCases = { lazy val testCase: TaprootWalletTestCases = {
upickle.default.read[TaprootWalletTestCases](lines)( upickle.default.read[TaprootWalletTestCases](lines)(
TaprootWalletTestCase.walletTestVectorReader using TaprootWalletTestCase.walletTestVectorReader
) )
} }

View File

@ -2,7 +2,7 @@ package org.bitcoins.core.crypto
import org.bitcoins.testkitcore.gen.CryptoGenerators import org.bitcoins.testkitcore.gen.CryptoGenerators
import org.bitcoins.testkitcore.util.BitcoinSUnitTest import org.bitcoins.testkitcore.util.BitcoinSUnitTest
import scodec.bits.HexStringSyntax import scodec.bits.ByteVector
import scala.util.{Failure, Try} import scala.util.{Failure, Try}
@ -28,9 +28,9 @@ class BIP39SeedTest extends BitcoinSUnitTest {
forAll(CryptoGenerators.entropy.bits128) { entropy => forAll(CryptoGenerators.entropy.bits128) { entropy =>
val attempt = Try { BIP39Seed.fromBytes(entropy.toByteVector.drop(1)) } val attempt = Try { BIP39Seed.fromBytes(entropy.toByteVector.drop(1)) }
assert(attempt.isFailure) assert(attempt.isFailure)
val exc = attempt.asInstanceOf[Failure[_]].exception val exc = attempt.asInstanceOf[Failure[?]].exception
assert(exc.getMessage contains "Seed must be between") assert(exc.getMessage `contains` "Seed must be between")
} }
} }
@ -38,16 +38,16 @@ class BIP39SeedTest extends BitcoinSUnitTest {
forAll(CryptoGenerators.entropy.bits256) { entropy => forAll(CryptoGenerators.entropy.bits256) { entropy =>
val attempt = Try { val attempt = Try {
BIP39Seed.fromBytes( BIP39Seed.fromBytes(
(entropy ++ entropy).toByteVector ++ hex"c" (entropy ++ entropy).toByteVector ++ ByteVector.fromValidHex("c")
) // one byte too much ) // one byte too much
} }
assert(attempt.isFailure) assert(attempt.isFailure)
val exc = attempt val exc = attempt
.asInstanceOf[Failure[_]] .asInstanceOf[Failure[?]]
.exception .exception
assert(exc.getMessage contains "Seed must be between") assert(exc.getMessage `contains` "Seed must be between")
} }
} }
} }

View File

@ -1,6 +1,6 @@
package org.bitcoins.core.crypto package org.bitcoins.core.crypto
import org.bitcoins.core.crypto.ExtKeyVersion._ import org.bitcoins.core.crypto.ExtKeyVersion.*
import org.bitcoins.core.hd.BIP32Path import org.bitcoins.core.hd.BIP32Path
import org.bitcoins.core.number.UInt32 import org.bitcoins.core.number.UInt32
import org.bitcoins.testkitcore.gen.{ import org.bitcoins.testkitcore.gen.{
@ -9,7 +9,7 @@ import org.bitcoins.testkitcore.gen.{
NumberGenerator NumberGenerator
} }
import org.bitcoins.testkitcore.util.BitcoinSUnitTest import org.bitcoins.testkitcore.util.BitcoinSUnitTest
import scodec.bits.HexStringSyntax import scodec.bits.ByteVector
import scala.util.{Failure, Success, Try} import scala.util.{Failure, Success, Try}
@ -101,7 +101,7 @@ class ExtKeyTest extends BitcoinSUnitTest {
// https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#test-vectors
it must "pass the test vectors in BIP32" in { it must "pass the test vectors in BIP32" in {
// master key // master key
val seedBytes = hex"000102030405060708090a0b0c0d0e0f" val seedBytes = ByteVector.fromValidHex("000102030405060708090a0b0c0d0e0f")
val path = BIP32Path.empty val path = BIP32Path.empty
@ -176,7 +176,8 @@ class ExtKeyTest extends BitcoinSUnitTest {
it must "pass test vector 2 in BIP32" in { it must "pass test vector 2 in BIP32" in {
val seedBytes = val seedBytes =
hex"fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542" ByteVector.fromValidHex(
"fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542")
val masterPriv = val masterPriv =
ExtPrivateKey(LegacyMainNetPriv, Some(seedBytes), BIP32Path.empty) ExtPrivateKey(LegacyMainNetPriv, Some(seedBytes), BIP32Path.empty)
@ -252,7 +253,8 @@ class ExtKeyTest extends BitcoinSUnitTest {
it must "pass test vector 3 in BIP32" in { it must "pass test vector 3 in BIP32" in {
val seedBytes = val seedBytes =
hex"4b381541583be4423346c643850da4b320e46a87ae3d2a4e6da11eba819cd4acba45d239319ac14f863b8d5ab5a0d0c64d2e8a1e7d1457df2e5a3c51c73235be" ByteVector.fromValidHex(
"4b381541583be4423346c643850da4b320e46a87ae3d2a4e6da11eba819cd4acba45d239319ac14f863b8d5ab5a0d0c64d2e8a1e7d1457df2e5a3c51c73235be")
val masterPrivKey = val masterPrivKey =
ExtPrivateKey(LegacyMainNetPriv, Some(seedBytes), BIP32Path.empty) ExtPrivateKey(LegacyMainNetPriv, Some(seedBytes), BIP32Path.empty)
@ -278,7 +280,8 @@ class ExtKeyTest extends BitcoinSUnitTest {
it must "pass test vector 4 in BIP32" in { it must "pass test vector 4 in BIP32" in {
val seedBytes = val seedBytes =
hex"3ddd5602285899a946114506157c7997e5444528f3003f6134712147db19b678" ByteVector.fromValidHex(
"3ddd5602285899a946114506157c7997e5444528f3003f6134712147db19b678")
val masterPrivKey = val masterPrivKey =
ExtPrivateKey(LegacyMainNetPriv, Some(seedBytes), BIP32Path.empty) ExtPrivateKey(LegacyMainNetPriv, Some(seedBytes), BIP32Path.empty)
@ -473,7 +476,8 @@ class ExtKeyTest extends BitcoinSUnitTest {
it must "not serialize a ExtPrivateKey to string" in { it must "not serialize a ExtPrivateKey to string" in {
val seedBytes = val seedBytes =
hex"4b381541583be4423346c643850da4b320e46a87ae3d2a4e6da11eba819cd4acba45d239319ac14f863b8d5ab5a0d0c64d2e8a1e7d1457df2e5a3c51c73235be" ByteVector.fromValidHex(
"4b381541583be4423346c643850da4b320e46a87ae3d2a4e6da11eba819cd4acba45d239319ac14f863b8d5ab5a0d0c64d2e8a1e7d1457df2e5a3c51c73235be")
val masterPriv = val masterPriv =
ExtPrivateKey(LegacyMainNetPriv, Some(seedBytes), BIP32Path.empty) ExtPrivateKey(LegacyMainNetPriv, Some(seedBytes), BIP32Path.empty)

View File

@ -3,7 +3,7 @@ package org.bitcoins.core.crypto
import org.bitcoins.testkitcore.gen.CryptoGenerators import org.bitcoins.testkitcore.gen.CryptoGenerators
import org.bitcoins.testkitcore.util.BitcoinSUnitTest import org.bitcoins.testkitcore.util.BitcoinSUnitTest
import org.scalatest.Assertion import org.scalatest.Assertion
import scodec.bits.{BinStringSyntax, BitVector, ByteVector} import scodec.bits.{BitVector, ByteVector}
import ujson._ import ujson._
import upickle.default._ import upickle.default._
@ -60,7 +60,7 @@ class MnemonicCodeTest extends BitcoinSUnitTest {
it must "fail to generate mnemonics from entropy of bad length" in { it must "fail to generate mnemonics from entropy of bad length" in {
def testEntropyFailure(entropy: BitVector): Assertion = { def testEntropyFailure(entropy: BitVector): Assertion = {
val short = entropy.drop(1) val short = entropy.drop(1)
val long = entropy ++ bin"1" val long = entropy ++ BitVector.fromValidHex("1")
assertThrows[IllegalArgumentException](MnemonicCode.fromEntropy(short)) assertThrows[IllegalArgumentException](MnemonicCode.fromEntropy(short))
assertThrows[IllegalArgumentException](MnemonicCode.fromEntropy(long)) assertThrows[IllegalArgumentException](MnemonicCode.fromEntropy(long))
} }
@ -79,12 +79,12 @@ class MnemonicCodeTest extends BitcoinSUnitTest {
assert(attempt.isFailure) assert(attempt.isFailure)
val exc = attempt val exc = attempt
.asInstanceOf[Failure[_]] .asInstanceOf[Failure[?]]
.exception .exception
val message = exc.getMessage val message = exc.getMessage
message contains "Entropy cannot be longer" message `contains` "Entropy cannot be longer"
} }
} }
@ -99,11 +99,11 @@ class MnemonicCodeTest extends BitcoinSUnitTest {
} }
assert(attempt.isFailure) assert(attempt.isFailure)
val exc = attempt val exc = attempt
.asInstanceOf[Failure[_]] .asInstanceOf[Failure[?]]
.exception .exception
val message = exc.getMessage val message = exc.getMessage
assert(message contains "Entropy must be at least") assert(message `contains` "Entropy must be at least")
} }
} }
@ -113,8 +113,8 @@ class MnemonicCodeTest extends BitcoinSUnitTest {
val codeT = Try(MnemonicCode.fromEntropy(e.drop(1))) val codeT = Try(MnemonicCode.fromEntropy(e.drop(1)))
assert(codeT.isFailure) assert(codeT.isFailure)
val exc = codeT.asInstanceOf[Failure[_]].exception val exc = codeT.asInstanceOf[Failure[?]].exception
assert(exc.getMessage contains "Entropy must be a multiple") assert(exc.getMessage `contains` "Entropy must be a multiple")
} }
} }
@ -151,8 +151,8 @@ class MnemonicCodeTest extends BitcoinSUnitTest {
} }
assert(fromWordsT.isFailure) assert(fromWordsT.isFailure)
val exc = fromWordsT.asInstanceOf[Failure[_]].exception val exc = fromWordsT.asInstanceOf[Failure[?]].exception
assert(exc.getMessage contains "checksum is not valid") assert(exc.getMessage `contains` "checksum is not valid")
} }
it must "fail to generate mnemonic codes from word vectors of bad length" in { it must "fail to generate mnemonic codes from word vectors of bad length" in {
@ -161,12 +161,12 @@ class MnemonicCodeTest extends BitcoinSUnitTest {
assert(attempt.isFailure) assert(attempt.isFailure)
val exc = attempt val exc = attempt
.asInstanceOf[Failure[_]] .asInstanceOf[Failure[?]]
.exception .exception
val message = exc.getMessage val message = exc.getMessage
assert(message contains "Number of words") assert(message `contains` "Number of words")
} }
forAll(CryptoGenerators.mnemonicPhrase) { phrase => forAll(CryptoGenerators.mnemonicPhrase) { phrase =>
@ -175,11 +175,11 @@ class MnemonicCodeTest extends BitcoinSUnitTest {
assert(attempt.isFailure) assert(attempt.isFailure)
val exc = attempt val exc = attempt
.asInstanceOf[Failure[_]] .asInstanceOf[Failure[?]]
.exception .exception
val message = exc.getMessage val message = exc.getMessage
assert(message contains "Number of words") assert(message `contains` "Number of words")
} }
} }

View File

@ -36,7 +36,7 @@ class BIP32PathTest extends BitcoinSUnitTest {
it must "have varargs and vector constructors what work the same way" in { it must "have varargs and vector constructors what work the same way" in {
forAll(HDGenerators.bip32Path) { bip32 => forAll(HDGenerators.bip32Path) { bip32 =>
assert(BIP32Path(bip32.path) == BIP32Path(bip32.path: _*)) assert(BIP32Path(bip32.path) == BIP32Path(bip32.path*))
} }
} }

View File

@ -38,13 +38,13 @@ class CurrencyUnitTest extends BitcoinSUnitTest {
} }
it must "have Long syntax" in { it must "have Long syntax" in {
forAll(Gen.choose(0, Satoshis.max.toLong / 100000000)) { num => forAll(Gen.choose(0L, Satoshis.max.toLong / 100000000)) { num =>
assert(num.bitcoins == Bitcoins(num)) assert(num.bitcoins == Bitcoins(num))
assert(num.bitcoin == Bitcoins(num)) assert(num.bitcoin == Bitcoins(num))
assert(num.BTC == Bitcoins(num)) assert(num.BTC == Bitcoins(num))
} }
forAll(Gen.choose(0, Satoshis.max.toLong)) { num => forAll(Gen.choose(0L, Satoshis.max.toLong)) { num =>
assert(num.satoshis == Satoshis(num)) assert(num.satoshis == Satoshis(num))
assert(num.satoshi == Satoshis(num)) assert(num.satoshi == Satoshis(num))
assert(num.sats == Satoshis(num)) assert(num.sats == Satoshis(num))

View File

@ -6,7 +6,7 @@ import org.bitcoins.crypto.SipHashKey
import org.bitcoins.testkitcore.gen.NumberGenerator import org.bitcoins.testkitcore.gen.NumberGenerator
import org.bitcoins.testkitcore.util.BitcoinSUnitTest import org.bitcoins.testkitcore.util.BitcoinSUnitTest
import org.scalacheck.Gen import org.scalacheck.Gen
import scodec.bits.{BinStringSyntax, ByteVector} import scodec.bits.{BitVector, ByteVector}
class GCSTest extends BitcoinSUnitTest { class GCSTest extends BitcoinSUnitTest {
behavior of "GCS" behavior of "GCS"
@ -18,7 +18,7 @@ class GCSTest extends BitcoinSUnitTest {
val encoding = GCS.golombEncode(item = original, p = p) val encoding = GCS.golombEncode(item = original, p = p)
assert(encoding == bin"000") assert(encoding == BitVector.fromValidBin("000"))
val decode = GCS.golombDecode(codedItem = encoding, p = p) val decode = GCS.golombDecode(codedItem = encoding, p = p)
@ -31,7 +31,7 @@ class GCSTest extends BitcoinSUnitTest {
val encoding = GCS.golombEncode(item = original, p = p) val encoding = GCS.golombEncode(item = original, p = p)
assert(encoding == bin"001") assert(encoding == BitVector.fromValidBin("001"))
val decode = GCS.golombDecode(codedItem = encoding, p = p) val decode = GCS.golombDecode(codedItem = encoding, p = p)
@ -44,7 +44,7 @@ class GCSTest extends BitcoinSUnitTest {
val encoding = GCS.golombEncode(item = original, p = p) val encoding = GCS.golombEncode(item = original, p = p)
assert(encoding == bin"010") assert(encoding == BitVector.fromValidBin("010"))
val decode = GCS.golombDecode(codedItem = encoding, p = p) val decode = GCS.golombDecode(codedItem = encoding, p = p)
@ -57,7 +57,7 @@ class GCSTest extends BitcoinSUnitTest {
val encoding = GCS.golombEncode(item = original, p = p) val encoding = GCS.golombEncode(item = original, p = p)
assert(encoding == bin"011") assert(encoding == BitVector.fromValidBin("011"))
val decode = GCS.golombDecode(codedItem = encoding, p = p) val decode = GCS.golombDecode(codedItem = encoding, p = p)
@ -70,7 +70,7 @@ class GCSTest extends BitcoinSUnitTest {
val encoding = GCS.golombEncode(item = original, p = p) val encoding = GCS.golombEncode(item = original, p = p)
assert(encoding == bin"1000") assert(encoding == BitVector.fromValidBin("1000"))
val decode = GCS.golombDecode(codedItem = encoding, p = p) val decode = GCS.golombDecode(codedItem = encoding, p = p)
@ -83,7 +83,7 @@ class GCSTest extends BitcoinSUnitTest {
val encoding = GCS.golombEncode(item = original, p = p) val encoding = GCS.golombEncode(item = original, p = p)
assert(encoding == bin"1001") assert(encoding == BitVector.fromValidBin("1001"))
val decode = GCS.golombDecode(codedItem = encoding, p = p) val decode = GCS.golombDecode(codedItem = encoding, p = p)
@ -96,7 +96,7 @@ class GCSTest extends BitcoinSUnitTest {
val encoding = GCS.golombEncode(item = original, p = p) val encoding = GCS.golombEncode(item = original, p = p)
assert(encoding == bin"1010") assert(encoding == BitVector.fromValidBin("1010"))
val decode = GCS.golombDecode(codedItem = encoding, p = p) val decode = GCS.golombDecode(codedItem = encoding, p = p)
@ -109,7 +109,7 @@ class GCSTest extends BitcoinSUnitTest {
val encoding = GCS.golombEncode(item = original, p = p) val encoding = GCS.golombEncode(item = original, p = p)
assert(encoding == bin"1011") assert(encoding == BitVector.fromValidBin("1011"))
val decode = GCS.golombDecode(codedItem = encoding, p = p) val decode = GCS.golombDecode(codedItem = encoding, p = p)
@ -122,7 +122,7 @@ class GCSTest extends BitcoinSUnitTest {
val encoding = GCS.golombEncode(item = original, p = p) val encoding = GCS.golombEncode(item = original, p = p)
assert(encoding == bin"11000") assert(encoding == BitVector.fromValidBin("11000"))
val decode = GCS.golombDecode(codedItem = encoding, p = p) val decode = GCS.golombDecode(codedItem = encoding, p = p)
@ -135,7 +135,7 @@ class GCSTest extends BitcoinSUnitTest {
val encoding = GCS.golombEncode(item = original, p = p) val encoding = GCS.golombEncode(item = original, p = p)
assert(encoding == bin"11001") assert(encoding == BitVector.fromValidBin("11001"))
val decode = GCS.golombDecode(codedItem = encoding, p = p) val decode = GCS.golombDecode(codedItem = encoding, p = p)
@ -170,12 +170,12 @@ class GCSTest extends BitcoinSUnitTest {
val codedSet = GCS.encodeSortedSet(sortedItems, p) val codedSet = GCS.encodeSortedSet(sortedItems, p)
val coded0 = bin"000" val coded0 = BitVector.fromValidBin("000")
val coded1 = bin"001" val coded1 = BitVector.fromValidBin("001")
val coded2 = bin"010" val coded2 = BitVector.fromValidBin("010")
val coded3 = bin"011" val coded3 = BitVector.fromValidBin("011")
val coded4 = bin"1000" val coded4 = BitVector.fromValidBin("1000")
val coded5 = bin"1001" val coded5 = BitVector.fromValidBin("1001")
val expectedCodedSet = val expectedCodedSet =
coded0 ++ coded1 ++ coded2 ++ coded3 ++ coded4 ++ coded5 coded0 ++ coded1 ++ coded2 ++ coded3 ++ coded4 ++ coded5

View File

@ -79,7 +79,7 @@ class MilliSatoshisTest extends BitcoinSUnitTest {
it must "subtract msats" in { it must "subtract msats" in {
forAll(LnCurrencyUnitGen.milliSatoshisPair) { case (first, second) => forAll(LnCurrencyUnitGen.milliSatoshisPair) { case (first, second) =>
val subtracted = first subtractSafe second val subtracted = first `subtractSafe` second
val isPositive = (first.toBigInt - second.toBigInt) >= 0 val isPositive = (first.toBigInt - second.toBigInt) >= 0
assert(subtracted.isSuccess == isPositive) assert(subtracted.isSuccess == isPositive)

View File

@ -498,7 +498,7 @@ class DescriptorTest extends BitcoinSUnitTest {
) )
case x: ScriptPathTreeExpression => case x: ScriptPathTreeExpression =>
x.source.leafs.head.source x.source.leafs.head.source
.asInstanceOf[P2PKScriptExpression[_]] .asInstanceOf[P2PKScriptExpression[?]]
.source .source
.asInstanceOf[ExtXOnlyPublicKeyExpression] .asInstanceOf[ExtXOnlyPublicKeyExpression]
.ecPublicKeyExpression .ecPublicKeyExpression

View File

@ -6,7 +6,7 @@ import org.bitcoins.core.protocol.CompactSizeUInt
import org.bitcoins.testkitcore.gen.NumberGenerator import org.bitcoins.testkitcore.gen.NumberGenerator
import org.bitcoins.testkitcore.util.BitcoinSUnitTest import org.bitcoins.testkitcore.util.BitcoinSUnitTest
import org.scalacheck.Gen import org.scalacheck.Gen
import scodec.bits.{ByteVector, HexStringSyntax} import scodec.bits.ByteVector
class RawAddrV2MessageSerializerTest extends BitcoinSUnitTest { class RawAddrV2MessageSerializerTest extends BitcoinSUnitTest {
@ -108,7 +108,7 @@ class RawAddrV2MessageSerializerTest extends BitcoinSUnitTest {
IPv4AddrV2Message( IPv4AddrV2Message(
UInt32(4523), UInt32(4523),
CompactSizeUInt(UInt64(53453453L)), CompactSizeUInt(UInt64(53453453L)),
InetAddress.getByAddress(hex"00000000".toArray), InetAddress.getByAddress(ByteVector.fromValidHex("00000000").toArray),
UInt16(8333) UInt16(8333)
) )
@ -125,7 +125,8 @@ class RawAddrV2MessageSerializerTest extends BitcoinSUnitTest {
val msg = IPv6AddrV2Message( val msg = IPv6AddrV2Message(
UInt32(4523), UInt32(4523),
CompactSizeUInt(UInt64(53453453L)), CompactSizeUInt(UInt64(53453453L)),
InetAddress.getByAddress(hex"00000000000000000000000000000000".toArray), InetAddress.getByAddress(
ByteVector.fromValidHex("00000000000000000000000000000000").toArray),
UInt16(8333) UInt16(8333)
) )
@ -144,7 +145,7 @@ class RawAddrV2MessageSerializerTest extends BitcoinSUnitTest {
val msg = TorV2AddrV2Message( val msg = TorV2AddrV2Message(
UInt32(4523), UInt32(4523),
CompactSizeUInt(UInt64(53453453L)), CompactSizeUInt(UInt64(53453453L)),
hex"00000000000000000000", ByteVector.fromValidHex("00000000000000000000"),
UInt16(8333) UInt16(8333)
) )
@ -161,7 +162,8 @@ class RawAddrV2MessageSerializerTest extends BitcoinSUnitTest {
val msg = TorV3AddrV2Message( val msg = TorV3AddrV2Message(
UInt32(4523), UInt32(4523),
CompactSizeUInt(UInt64(53453453L)), CompactSizeUInt(UInt64(53453453L)),
hex"0000000000000000000000000000000000000000000000000000000000000000", ByteVector.fromValidHex(
"0000000000000000000000000000000000000000000000000000000000000000"),
UInt16(8333) UInt16(8333)
) )
@ -180,7 +182,8 @@ class RawAddrV2MessageSerializerTest extends BitcoinSUnitTest {
val msg = I2PAddrV2Message( val msg = I2PAddrV2Message(
UInt32(4523), UInt32(4523),
CompactSizeUInt(UInt64(53453453L)), CompactSizeUInt(UInt64(53453453L)),
hex"0000000000000000000000000000000000000000000000000000000000000000", ByteVector.fromValidHex(
"0000000000000000000000000000000000000000000000000000000000000000"),
UInt16(8333) UInt16(8333)
) )
@ -199,7 +202,7 @@ class RawAddrV2MessageSerializerTest extends BitcoinSUnitTest {
val msg = CJDNSAddrV2Message( val msg = CJDNSAddrV2Message(
UInt32(4523), UInt32(4523),
CompactSizeUInt(UInt64(53453453L)), CompactSizeUInt(UInt64(53453453L)),
hex"fc000000000000000000000000000000", ByteVector.fromValidHex("fc000000000000000000000000000000"),
UInt16(8333) UInt16(8333)
) )
@ -219,7 +222,7 @@ class RawAddrV2MessageSerializerTest extends BitcoinSUnitTest {
UInt32(4523), UInt32(4523),
CompactSizeUInt(UInt64(53453453L)), CompactSizeUInt(UInt64(53453453L)),
0x07, 0x07,
hex"00000000000000000000000000000000", ByteVector.fromValidHex("00000000000000000000000000000000"),
UInt16(8333) UInt16(8333)
) )

View File

@ -7,7 +7,7 @@ import org.bitcoins.core.protocol.CompactSizeUInt
import org.bitcoins.core.protocol.blockchain.{BlockHeader, MainNetChainParams} import org.bitcoins.core.protocol.blockchain.{BlockHeader, MainNetChainParams}
import org.bitcoins.crypto.{CryptoUtil, DoubleSha256Digest} import org.bitcoins.crypto.{CryptoUtil, DoubleSha256Digest}
import org.bitcoins.testkitcore.chain.ChainTestUtil import org.bitcoins.testkitcore.chain.ChainTestUtil
import scodec.bits.{ByteVector, HexStringSyntax} import scodec.bits.ByteVector
import java.time.Instant import java.time.Instant
import java.time.temporal.ChronoUnit import java.time.temporal.ChronoUnit
@ -146,7 +146,8 @@ class NetworkUtilTest extends BitcoinSUtilTest {
// the parsing of the remainder // the parsing of the remainder
it must "parse a byte vector with three messages in it" in { it must "parse a byte vector with three messages in it" in {
val bytes = val bytes =
hex"fabfb5da6d65726b6c65626c6f636b0097000000b4b6e45d00000020387191f7d488b849b4080fdf105c71269fc841a2f0f2944fc5dc785c830c716e37f36373098aae06a668cc74e388caf50ecdcb5504ce936490b4b72940e08859548c305dffff7f20010000000200000002ecd1c722709bfc241f8b94fc64034dcba2c95409dc4cd1d7b864e1128a04e5b044133327b04ff8ac576e7748a4dae4111f0c765dacbfe0c5a9fddbeb8f60d5af0105fabfb5da747800000000000000000000cc0100004413332702000000065b7f0f3eec398047e921037815aa41709b6243a1897f1423194b7558399ae0300000000017160014008dc9d88d1797305f3fbd30d2b36d6bde984a09feffffffe9145055d671fd705a09f028033da614b619205b9926fe5ebe45e15ae8b3231e0100000017160014d74cfac04bb0e6838c35f1f4a0a60d13655be2fbfeffffff797f8ff9c10fa618b6254343a648be995410e82c03fd8accb0de2271a3fb1abd00000000171600143ee832c09db48eca28a64a358ed7a01dbe52d31bfeffffffc794dba971b9479dfcbc662a3aacd641553bdb2418b15c0221c5dfd4471a7a70000000001716001452c13ba0314f7718c234ed6adfea6422ce03a545feffffffb7c3bf1762b15f3b0e0eaa5beb46fe96a9e2829a7413fd900b9b7e0d192ab64800000000171600143ee832c09db48eca28a64a358ed7a01dbe52d31bfeffffffb6ced6cb8dfc2f7f5b37561938ead3bc5ca4036e2b45d9738cc086a10eed4e010100000017160014aebb17e245fe8c98a75f0b6717fcadca30e491e2feffffff02002a7515000000001976a9148374ff8beb55ea2945039881ca26071b5749fafe88ac485620000000000017a91405d36a2b0bdedf3fc58bed6f9e4026f8934a2716876b050000fabfb5da686561646572730000000000010000001406e05800" ByteVector.fromValidHex(
"fabfb5da6d65726b6c65626c6f636b0097000000b4b6e45d00000020387191f7d488b849b4080fdf105c71269fc841a2f0f2944fc5dc785c830c716e37f36373098aae06a668cc74e388caf50ecdcb5504ce936490b4b72940e08859548c305dffff7f20010000000200000002ecd1c722709bfc241f8b94fc64034dcba2c95409dc4cd1d7b864e1128a04e5b044133327b04ff8ac576e7748a4dae4111f0c765dacbfe0c5a9fddbeb8f60d5af0105fabfb5da747800000000000000000000cc0100004413332702000000065b7f0f3eec398047e921037815aa41709b6243a1897f1423194b7558399ae0300000000017160014008dc9d88d1797305f3fbd30d2b36d6bde984a09feffffffe9145055d671fd705a09f028033da614b619205b9926fe5ebe45e15ae8b3231e0100000017160014d74cfac04bb0e6838c35f1f4a0a60d13655be2fbfeffffff797f8ff9c10fa618b6254343a648be995410e82c03fd8accb0de2271a3fb1abd00000000171600143ee832c09db48eca28a64a358ed7a01dbe52d31bfeffffffc794dba971b9479dfcbc662a3aacd641553bdb2418b15c0221c5dfd4471a7a70000000001716001452c13ba0314f7718c234ed6adfea6422ce03a545feffffffb7c3bf1762b15f3b0e0eaa5beb46fe96a9e2829a7413fd900b9b7e0d192ab64800000000171600143ee832c09db48eca28a64a358ed7a01dbe52d31bfeffffffb6ced6cb8dfc2f7f5b37561938ead3bc5ca4036e2b45d9738cc086a10eed4e010100000017160014aebb17e245fe8c98a75f0b6717fcadca30e491e2feffffff02002a7515000000001976a9148374ff8beb55ea2945039881ca26071b5749fafe88ac485620000000000017a91405d36a2b0bdedf3fc58bed6f9e4026f8934a2716876b050000fabfb5da686561646572730000000000010000001406e05800")
val (messages, leftover) = NetworkUtil.parseIndividualMessages(bytes) val (messages, leftover) = NetworkUtil.parseIndividualMessages(bytes)
assert(messages.length == 3) assert(messages.length == 3)

View File

@ -2,7 +2,7 @@ package org.bitcoins.crypto
import org.scalacheck.Gen import org.scalacheck.Gen
import org.scalatest.compatible.Assertion import org.scalatest.compatible.Assertion
import scodec.bits.{ByteVector, HexStringSyntax} import scodec.bits.ByteVector
class AesCryptTest extends BitcoinSCryptoTest { class AesCryptTest extends BitcoinSCryptoTest {
behavior of "AesEncrypt" behavior of "AesEncrypt"
@ -14,7 +14,7 @@ class AesCryptTest extends BitcoinSCryptoTest {
private def getIV(bytes: ByteVector): AesIV = AesIV.fromValidBytes(bytes) private def getIV(bytes: ByteVector): AesIV = AesIV.fromValidBytes(bytes)
val aesKey: AesKey = val aesKey: AesKey =
getKey(hex"12345678123456781234567812345678") getKey(ByteVector.fromValidHex("12345678123456781234567812345678"))
val badAesKey: AesKey = getKey(aesKey.bytes.reverse) val badAesKey: AesKey = getKey(aesKey.bytes.reverse)
@ -51,33 +51,38 @@ class AesCryptTest extends BitcoinSCryptoTest {
val first = val first =
TestVector( TestVector(
plainText = hex"76fe35880055e1fac950f484a815cd22", plainText = ByteVector.fromValidHex("76fe35880055e1fac950f484a815cd22"),
key = getKey(hex"2eefdf6ee2dbca83e7b7648a8f9d1897"), key =
getKey(ByteVector.fromValidHex("2eefdf6ee2dbca83e7b7648a8f9d1897")),
cipherText = AesEncryptedData( cipherText = AesEncryptedData(
cipherText = hex"974b22d3de46a58023ddb94dac574293", cipherText =
iv = getIV(hex"889dc64377f6d993ef713c995f9c1ee5") ByteVector.fromValidHex("974b22d3de46a58023ddb94dac574293"),
iv =
getIV(ByteVector.fromValidHex("889dc64377f6d993ef713c995f9c1ee5"))
) )
) )
runTest(first) runTest(first)
val second = TestVector( val second = TestVector(
plainText = hex"3a4f73044d035017d91883ebfc113da7", plainText = ByteVector.fromValidHex("3a4f73044d035017d91883ebfc113da7"),
key = getKey(hex"5ce91f97ed28fd5d1172e23eb17b1baa"), key = getKey(ByteVector.fromValidHex("5ce91f97ed28fd5d1172e23eb17b1baa")),
cipherText = AesEncryptedData( cipherText = AesEncryptedData(
cipherText = hex"f0ff04edc644388edb872237ac558367", cipherText =
iv = getIV(hex"3f91d29f81d48174b25a3d0143eb833c") ByteVector.fromValidHex("f0ff04edc644388edb872237ac558367"),
iv = getIV(ByteVector.fromValidHex("3f91d29f81d48174b25a3d0143eb833c"))
) )
) )
runTest(second) runTest(second)
val third = TestVector( val third = TestVector(
plainText = hex"5f6a62cb52309db4573bfed807e07bb2", plainText = ByteVector.fromValidHex("5f6a62cb52309db4573bfed807e07bb2"),
key = getKey(hex"c62bea08786568283dafabde6d699e0f"), key = getKey(ByteVector.fromValidHex("c62bea08786568283dafabde6d699e0f")),
cipherText = AesEncryptedData( cipherText = AesEncryptedData(
cipherText = hex"161bd64b0b4efe3561e949344e9efaaf", cipherText =
iv = getIV(hex"455014871cd34f8dcfd7c1e387987bff") ByteVector.fromValidHex("161bd64b0b4efe3561e949344e9efaaf"),
iv = getIV(ByteVector.fromValidHex("455014871cd34f8dcfd7c1e387987bff"))
) )
) )
@ -89,14 +94,15 @@ class AesCryptTest extends BitcoinSCryptoTest {
// echo foobar | openssl enc -aes-128-cfb -K 5ce91f97ed28fd5d1172e23eb17b1baa \ // echo foobar | openssl enc -aes-128-cfb -K 5ce91f97ed28fd5d1172e23eb17b1baa \
// -iv 455014871cd34f8dcfd7c1e387987bff -p -base64 -nosalt // -iv 455014871cd34f8dcfd7c1e387987bff -p -base64 -nosalt
it must "pass an openssl hard coded vector" in { it must "pass an openssl hard coded vector" in {
val key = getKey(hex"5CE91F97ED28FD5D1172E23EB17B1BAA") val key =
getKey(ByteVector.fromValidHex("5CE91F97ED28FD5D1172E23EB17B1BAA"))
val plainText = "foobar" val plainText = "foobar"
val plainBytesE = ByteVector.encodeUtf8(plainText) val plainBytesE = ByteVector.encodeUtf8(plainText)
val plainbytes = plainBytesE match { val plainbytes = plainBytesE match {
case Left(_) => fail(s"Unsuccessful encoding") case Left(_) => fail(s"Unsuccessful encoding")
case Right(b) => b case Right(b) => b
} }
val iv = getIV(hex"455014871CD34F8DCFD7C1E387987BFF") val iv = getIV(ByteVector.fromValidHex("455014871CD34F8DCFD7C1E387987BFF"))
// val expectedCipher = ByteVector.fromValidBase64("oE8HErg1lg==") // val expectedCipher = ByteVector.fromValidBase64("oE8HErg1lg==")
val encrypted = AesCrypt.encryptWithIV(plainbytes, iv, key) val encrypted = AesCrypt.encryptWithIV(plainbytes, iv, key)
@ -137,8 +143,9 @@ class AesCryptTest extends BitcoinSCryptoTest {
* KKbLXDQUy7ajmuIJm7ZR7ugaRubqGl1JwG+x5C451JXIFofnselHVTy/u8u0Or9nV2d7Kjy0 * KKbLXDQUy7ajmuIJm7ZR7ugaRubqGl1JwG+x5C451JXIFofnselHVTy/u8u0Or9nV2d7Kjy0
*/ */
it must "pass a hardcoded crypto-js vector where we decrypt with a key" in { it must "pass a hardcoded crypto-js vector where we decrypt with a key" in {
val key = getKey(hex"12345678123456781234567812345678") val key =
val iv = getIV(hex"87654321876543218765432187654321") getKey(ByteVector.fromValidHex("12345678123456781234567812345678"))
val iv = getIV(ByteVector.fromValidHex("87654321876543218765432187654321"))
val expectedCipher = ByteVector.fromValidBase64( val expectedCipher = ByteVector.fromValidBase64(
"KKbLXDQUy7ajmuIJm7ZR7ugaRubqGl1JwG+x5C451JXIFofnselHVTy/u8u0Or9nV2d7Kjy0" "KKbLXDQUy7ajmuIJm7ZR7ugaRubqGl1JwG+x5C451JXIFofnselHVTy/u8u0Or9nV2d7Kjy0"
) )
@ -252,8 +259,9 @@ class AesCryptTest extends BitcoinSCryptoTest {
} }
} }
val key = getKey(hex"e67a00b510bcff7f4a0101ff5f7fb690") val key =
val iv = getIV(hex"f43b7f80624e7f01123ac272beb1ff7f") getKey(ByteVector.fromValidHex("e67a00b510bcff7f4a0101ff5f7fb690"))
val iv = getIV(ByteVector.fromValidHex("f43b7f80624e7f01123ac272beb1ff7f"))
val plainText = "The quick brown fox jumps over the lazy dog." val plainText = "The quick brown fox jumps over the lazy dog."
val plainBytesE = ByteVector.encodeUtf8(plainText) val plainBytesE = ByteVector.encodeUtf8(plainText)
val plainbytes = plainBytesE match { val plainbytes = plainBytesE match {
@ -261,7 +269,8 @@ class AesCryptTest extends BitcoinSCryptoTest {
case Right(b) => b case Right(b) => b
} }
val expectedCipher = val expectedCipher =
hex"09697c53d3a1e5ec5a465231e536c70428f53cb7d4030a707e42daa338ce147ec2d55c865e85dfb5072a1bf31a977cf4" ByteVector.fromValidHex(
"09697c53d3a1e5ec5a465231e536c70428f53cb7d4030a707e42daa338ce147ec2d55c865e85dfb5072a1bf31a977cf4")
// test encrypting and decrypting ourselves // test encrypting and decrypting ourselves
{ {
@ -360,9 +369,9 @@ class AesCryptTest extends BitcoinSCryptoTest {
.filter(!AesKey.keylengths.contains(_)) .filter(!AesKey.keylengths.contains(_))
.map(NumberGenerator.bytevector(_)) .map(NumberGenerator.bytevector(_))
val first +: second +: _ = bytevectorGens val first +: second +: _ = bytevectorGens: @unchecked
val badKeyLenghts: Gen[ByteVector] = val badKeyLenghts: Gen[ByteVector] =
Gen.oneOf(first, second, bytevectorGens: _*) Gen.oneOf(first, second, bytevectorGens*)
forAll(badKeyLenghts) { bytes => forAll(badKeyLenghts) { bytes =>
assert(AesKey.fromBytes(bytes).isEmpty) assert(AesKey.fromBytes(bytes).isEmpty)
@ -380,7 +389,7 @@ class AesCryptTest extends BitcoinSCryptoTest {
} }
it must "not be constructable from invalid length bytes" in { it must "not be constructable from invalid length bytes" in {
val bytes = hex"12345" val bytes = ByteVector.fromValidHex("12345")
intercept[IllegalArgumentException] { intercept[IllegalArgumentException] {
AesIV.fromValidBytes(bytes) AesIV.fromValidBytes(bytes)
} }

View File

@ -696,7 +696,7 @@ trait DLCTest {
dlcOffer: TestDLCClient, dlcOffer: TestDLCClient,
dlcAccept: TestDLCClient, dlcAccept: TestDLCClient,
fundingTxF: Future[SetupDLC] => Future[Transaction], fundingTxF: Future[SetupDLC] => Future[Transaction],
publishTransaction: Transaction => Future[_] publishTransaction: Transaction => Future[?]
)(implicit ec: ExecutionContext): Future[(SetupDLC, SetupDLC)] = { )(implicit ec: ExecutionContext): Future[(SetupDLC, SetupDLC)] = {
val offerSigReceiveP = { val offerSigReceiveP = {
Promise[(CETSignatures, PartialSignature)]() Promise[(CETSignatures, PartialSignature)]()

View File

@ -344,7 +344,7 @@ sealed abstract class CryptoGenerators {
mGen.flatMap { m => mGen.flatMap { m =>
val upperBound = m.toInt * 2 - 2 val upperBound = m.toInt * 2 - 2
val randGen = Gen.chooseNum(0L, upperBound).map(UInt64(_)) val randGen = Gen.chooseNum(0, upperBound).map(UInt64(_))
randGen.map(rand => (p, m, rand)) randGen.map(rand => (p, m, rand))
} }

View File

@ -19,13 +19,13 @@ trait CurrencyUnitGenerator {
def currencyUnit: Gen[CurrencyUnit] = Gen.oneOf(satoshis, bitcoins) def currencyUnit: Gen[CurrencyUnit] = Gen.oneOf(satoshis, bitcoins)
def positiveSatoshis: Gen[Satoshis] = def positiveSatoshis: Gen[Satoshis] =
Gen.choose(0, Long.MaxValue).map(Satoshis.apply) Gen.choose(0L, Long.MaxValue).map(Satoshis.apply)
/** Generates a postiive satoshi value that is 'realistic'. This current /** Generates a postiive satoshi value that is 'realistic'. This current
* 'realistic' range is from 0 to 1,000,000 bitcoin * 'realistic' range is from 0 to 1,000,000 bitcoin
*/ */
def positiveRealistic: Gen[Satoshis] = def positiveRealistic: Gen[Satoshis] =
Gen.choose(0, Bitcoins(1000000).satoshis.toLong).map { n => Gen.choose(0L, Bitcoins(1000000).satoshis.toLong).map { n =>
Satoshis(n) Satoshis(n)
} }
} }

View File

@ -176,7 +176,7 @@ trait TLVGen {
outcomes <- Gen.listOfN(numOutcomes, StringGenerators.genString) outcomes <- Gen.listOfN(numOutcomes, StringGenerators.genString)
totalInput <- totalInput <-
Gen Gen
.choose(numOutcomes + 1, Long.MaxValue / 10000L) .choose(numOutcomes + 1L, Long.MaxValue / 10000L)
.map(Satoshis.apply) .map(Satoshis.apply)
(contractDescriptor, _) = (contractDescriptor, _) =
DLCTestUtil.genContractDescriptors(outcomes.toVector, totalInput) DLCTestUtil.genContractDescriptors(outcomes.toVector, totalInput)
@ -195,7 +195,7 @@ trait TLVGen {
numDigits <- Gen.choose(3, 7) numDigits <- Gen.choose(3, 7)
totalInput <- totalInput <-
Gen Gen
.choose(numDigits + 1, Long.MaxValue / 10000L) .choose(numDigits + 1L, Long.MaxValue / 10000L)
.map(Satoshis.apply) .map(Satoshis.apply)
(contractDescriptor, _) = (contractDescriptor, _) =
DLCTestUtil.genMultiDigitContractInfo(numDigits, totalInput) DLCTestUtil.genMultiDigitContractInfo(numDigits, totalInput)

View File

@ -87,7 +87,7 @@ object TransactionGenerators {
accum accum
} else { } else {
val amt = Gen val amt = Gen
.choose(100, remainingAmount.toBigDecimal.toLongExact) .choose(100L, remainingAmount.toBigDecimal.toLongExact)
.map(n => Satoshis(n)) .map(n => Satoshis(n))
.sampleSome .sampleSome
loop(remaining - 1, remainingAmount - amt, amt +: accum) loop(remaining - 1, remainingAmount - amt, amt +: accum)
@ -1040,7 +1040,7 @@ object TransactionGenerators {
txLockTime: UInt32 txLockTime: UInt32
): Gen[ScriptNumber] = { ): Gen[ScriptNumber] = {
if (txLockTime < TransactionConstants.locktimeThreshold) { if (txLockTime < TransactionConstants.locktimeThreshold) {
Gen.choose(0, txLockTime.toLong).map(ScriptNumber(_)) Gen.choose(0L, txLockTime.toLong).map(ScriptNumber(_))
} else { } else {
Gen Gen
.choose( .choose(

View File

@ -28,7 +28,7 @@ trait LnCurrencyUnitGen {
} yield PicoBitcoins(amount) } yield PicoBitcoins(amount)
def positivePicoBitcoin: Gen[PicoBitcoins] = { def positivePicoBitcoin: Gen[PicoBitcoins] = {
Gen.choose(0, PicoBitcoins.max.toLong).map(PicoBitcoins(_)) Gen.choose(0L, PicoBitcoins.max.toLong).map(PicoBitcoins(_))
} }
def lnCurrencyUnit: Gen[LnCurrencyUnit] = def lnCurrencyUnit: Gen[LnCurrencyUnit] =
@ -39,7 +39,7 @@ trait LnCurrencyUnitGen {
} }
def realisticLnInvoice: Gen[LnCurrencyUnit] = { def realisticLnInvoice: Gen[LnCurrencyUnit] = {
val gen = Gen.choose(0, LnPolicy.maxAmountMSat.toLong) val gen = Gen.choose(0L, LnPolicy.maxAmountMSat.toLong)
val msat = gen.map(MilliSatoshis(_)) val msat = gen.map(MilliSatoshis(_))
msat.map(LnCurrencyUnits.fromMSat(_)) msat.map(LnCurrencyUnits.fromMSat(_))
} }

View File

@ -186,7 +186,7 @@ sealed abstract class LnInvoiceGen {
} yield LnInvoiceSignature(version, sig) } yield LnInvoiceSignature(version, sig)
def invoiceTimestamp: Gen[UInt64] = { def invoiceTimestamp: Gen[UInt64] = {
Gen.choose(0, LnInvoice.MAX_TIMESTAMP_U64.toLong).map(UInt64(_)) Gen.choose(0L, LnInvoice.MAX_TIMESTAMP_U64.toLong).map(UInt64(_))
} }
def lnInvoice(privateKey: ECPrivateKey): Gen[LnInvoice] = { def lnInvoice(privateKey: ECPrivateKey): Gen[LnInvoice] = {