From 9638b37fd5bb9eecce29a06b9f9ed49e52705292 Mon Sep 17 00:00:00 2001 From: Stephan February Date: Mon, 21 Aug 2023 09:03:07 +0800 Subject: [PATCH 1/6] Prep for v2.0.0-rc2 - Release candidate 2 preparations. Double-checked spendability of large output transactions after some minor tweaks. --- CHANGELOG.md | 5 +++++ LICENSE | 2 +- lib/src/coin.dart | 1 - lib/src/transaction/transaction.dart | 1 - pubspec.yaml | 2 +- test/transaction/transaction_test.dart | 23 +++++++++++++++++------ 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e72307..ead08e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.0-rc2 +- Large data Transaction fixes. There was a bug which prevented the crafting of + large data transactions, i.e transactions with outputs that have PUSHDATA operations + that pushed more than 65k bytes onto the stack. + ## 2.0.0-rc1 Version 2.x is a major refactor of the internals. diff --git a/LICENSE b/LICENSE index f31148d..c56a1e0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2019-2020 Stephan M. February +Copyright (c) 2019-2023 Stephan M. February Copyright (c) 2018-2019 Yours Inc. diff --git a/lib/src/coin.dart b/lib/src/coin.dart index 96c5897..cff6421 100644 --- a/lib/src/coin.dart +++ b/lib/src/coin.dart @@ -1,6 +1,5 @@ import 'dart:math'; -import 'package:dartsv/src/transaction/preconditions.dart'; import 'package:decimal/decimal.dart'; /** diff --git a/lib/src/transaction/transaction.dart b/lib/src/transaction/transaction.dart index 63cba5d..11dfd7b 100644 --- a/lib/src/transaction/transaction.dart +++ b/lib/src/transaction/transaction.dart @@ -77,7 +77,6 @@ class Transaction { final ECDSASigner _dsaSigner = ECDSASigner(null, HMac(_sha256Digest, 64)); final ECDomainParameters _domainParams = ECDomainParameters('secp256k1'); - BigInt? _fee; bool _changeScriptFlag = false; var CURRENT_VERSION = 1; diff --git a/pubspec.yaml b/pubspec.yaml index a4aa38c..2a7574f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: dartsv description: Dart Library for interacting with the Bitcoin network. This library is especially well-suited for use in developing Flutter applications. -version: 2.0.0-rc1 +version: 2.0.0-rc2 homepage: https://github.com/twostack/dartsv environment: diff --git a/test/transaction/transaction_test.dart b/test/transaction/transaction_test.dart index 208f3a5..1fad161 100644 --- a/test/transaction/transaction_test.dart +++ b/test/transaction/transaction_test.dart @@ -829,12 +829,15 @@ main() { testLargeOutput(File file) async { - var fundingTxHex = "0200000004419066dec2905bf2dd48b4983efb874e7d727fe42a888480df31168060bd9faa0000000049483045022100fd73b305714b5ecfe1ea7c37a73633ffba06a9aea218e2e431aaa33d331fac2d02203ce9c16d7abc4f1e66ffa076356ec3bfe08878bca08629fe7db75541c251007541fefffffff7aa7a800840c04eddcad5380a472dae7829e0b3f4cc0a7f943dd95deaefd4a00000000048473044022056a6436a3591e6975bf31c8265f250a64581b46aa56822a31a483006e802ae3602202e0909897f39dc1dc2e2b18ef5842c08a0a6e9e6552abe13a75dcf8fd820ce5541feffffffc82066e8120f1f2a82b1b485ce1170a7c4a148af4725146a6d7c05f64ea87c6d000000004847304402200269b3b8c43faf4a318adb87a06d6b5935a9348102cd2136fe9be1ef7c45047e02203151d9736d7f1d86467d8571dd0f0d207094c14492eb5312957b296df12e8b9e41feffffff806d7cf11b9766d6cc0fcf7d9644ffcd46b97a56bb19158e1d9c964620f684ac010000006b4830450221008403260de0b52f63ee74a758e1ffd1d78f25faea99b04914d124f2fd909f3b10022018a3b712e1ee431ba5d08116f6540361db2f2e1210444d1375758459555c435d412102726a0bf178f2cd5986fcf0ad788058d0bc1eda7dbc97fa31e1d18fdde4522ebffeffffff0200e1f505000000001976a91488d9931ea73d60eaf7e5671efc0552b912911f2a88acb7181400000000001976a91451951cf496faa66920dbd3eda83792603a83f95088aca2070000"; + //fundingTxHex with at least 0.5 bitcoin locked in Output[0] and spendable by "privateKey" variable + var fundingTxHex = "02000000066073650adc5592616f3e103a7fc44afe2c8bca12c4e74745df40f3fa75385b6a0000000049483045022100ef53112f0385c43662f771997e4c764981fc5849f2fd714c5acea0aed0e2946e02202344aed194ed5aa47b946911b19df20bdbd9ab4d643632ed719d60942e2693c041feffffff22954849265e24fb0ceb9e51169cb4fc1c5b19f23fa57faa19980a92abecedc10000000049483045022100850575b97f912c6193f743d51cefc60bb5feea59558956db396f4849809d4d0b02200bd171eb869cf51dbb6aad9ee120520b6bc95f581ca365442970593dcfb7155a41feffffff750362cdfb3abf942ef2d9c1e6fe2e09e5e043a4a210944b9a28efe7662566420000000049483045022100f576e3e24d4e54be21c5e6adc6fccda99c59c3bb5d29ef73be29f7c7fc62e542022036e45ebf8bc95d043ec04cad88f200263de04241f653cca7458ed2051afb19ba41feffffff89cf145b3682c4d9508f7ce7e055d86090c279a1cfc069831508207ed3cd6ef3000000004847304402202e1b00a4f95a2a234c5f7c7e235b9e71c495d746b882930c4acebbe6f0ef51c202205155b873e7d5c7d64a04670d8f97d981fdeded3a05a5cadcfec86e23ce8c117741feffffffc4974ba60edc773723401d2215f9d286b872db4b6083c187e03aaf70c6f27a6b010000006a47304402201ff0969a3ebe8efa94a052c27a27bae21f83917f8f8b70c5e98abcb208b7ebe702200a7ceb66f03e352415145ff9d73edb559270a9a78526b1e67cd676f1217e1ceb4121028d6f19251b58baf0f561865adefc4550bfa72e94813b860d6095038fe1f32b22feffffff2a3c48e411ebf605dc03854321c157ec1ed8c0ffa7b0236d8f539d4f1099896e000000004847304402201834041195743a7821ea24c9a977f011a2be4cf717fcf8d3853b62f81cdd917c0220086da5e9bd72dac4ad89fec127572ad8b153c5a52cbe0bcf59f6dddd334eef1141feffffff0280f0fa02000000001976a91488d9931ea73d60eaf7e5671efc0552b912911f2a88ac3d2c1000000000001976a91453b4272cd0a2f32d3e1079822a90097dfff1a07688ac37090000"; var fundingTx = Transaction.fromHex(fundingTxHex); var outputAmount = fundingTx.outputs[0].satoshis; var fundingOutput = fundingTx.outputs[0]; var changeAddress = Address.fromPublicKey(privateKey.publicKey, NetworkType.TEST); + //address : mszYqVnqKoQx4jcTdJXxwKAissE3Jbrrc1 + var largeData = await file; var dataLockBuilder = UnspendableDataLockBuilder(largeData.readAsBytesSync()); @@ -845,14 +848,15 @@ main() { var unlocker = P2PKHUnlockBuilder(privateKey.publicKey); - var tx = TransactionBuilder() + var builder = TransactionBuilder() .spendFromOutpointWithSigner(signer, outpoint, TransactionInput.MAX_SEQ_NUMBER, unlocker) .spendToPKH(toAddress, BigInt.from(100000)) - .spendToLockBuilder(dataLockBuilder, BigInt.zero) + .spendToLockBuilder(dataLockBuilder, BigInt.one) .sendChangeToPKH(changeAddress) - .withFeePerKb(1000) - .withOption(TransactionOption.DISABLE_DUST_OUTPUTS) - .build(true); + .withFeePerKb(50) + .withOption(TransactionOption.DISABLE_DUST_OUTPUTS); + + var tx = builder.build(true); // we then extract the signature from the first input var inputIndex = 0; @@ -864,6 +868,9 @@ main() { var interpreter = Interpreter(); interpreter.correctlySpends(scriptSig!, scriptPubkey, tx, inputIndex, flags, Coin.ofSat(outputAmount )); + + print("[ \n\n\n ${tx.serialize()} \n\n\n ]"); + print("Miner fee - ${builder.getFee()}"); } @@ -874,4 +881,8 @@ main() { test('can craft a large output txn > 65535 bytes', () async { await testLargeOutput(File("${Directory.current.path}/test/data/bitcoin_whitepaper.pdf")); }); + + test('print address', () async { + print(Address.fromPublicKey(privateKey.publicKey, NetworkType.TEST)); + }); } \ No newline at end of file From 4c85dfecab417741d7fe6f206f32532b3808a157 Mon Sep 17 00:00:00 2001 From: Stephan February Date: Mon, 21 Aug 2023 09:06:47 +0800 Subject: [PATCH 2/6] SDK version minimum set to 2.17 - Set absolute minimum SDk version to 2.17 to take advantage of enhanced enums while having max compatibility. --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 2a7574f..c1bf2ab 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 2.0.0-rc2 homepage: https://github.com/twostack/dartsv environment: - sdk: '>=2.18.0 <4.0.0' + sdk: '>=2.17.0 <4.0.0' dependencies: hex: ^0.2.0 From ae8211f88f8973baacd67b556bc1881315072fb9 Mon Sep 17 00:00:00 2001 From: Stephan February Date: Mon, 21 Aug 2023 09:13:08 +0800 Subject: [PATCH 3/6] Set version of Dart-SDK for build --- .github/workflows/dart.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index 11e18c7..bb30647 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest container: - image: google/dart:latest + image: dart:3.1-sdk steps: - uses: actions/checkout@v2 From be6a99c47e3b9e3f6ab5007a4476b83b9f9ea277 Mon Sep 17 00:00:00 2001 From: Stephan February Date: Mon, 21 Aug 2023 09:14:48 +0800 Subject: [PATCH 4/6] Update dart.yml --- .github/workflows/dart.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index bb30647..fd42f52 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest container: - image: dart:3.1-sdk + image: dart:latest steps: - uses: actions/checkout@v2 From 470f3458ea31dc6ee4a6f56630bcefd9afc38faa Mon Sep 17 00:00:00 2001 From: Stephan February Date: Mon, 21 Aug 2023 09:18:12 +0800 Subject: [PATCH 5/6] Update dart.yml --- .github/workflows/dart.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index fd42f52..c3e6bf9 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -15,7 +15,7 @@ jobs: image: dart:latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install dependencies run: pub get - name: Run tests From eb42707946278712abf7ce6b19724be8338ec665 Mon Sep 17 00:00:00 2001 From: Stephan February Date: Mon, 21 Aug 2023 09:24:21 +0800 Subject: [PATCH 6/6] Change to Setup-Dart --- .github/workflows/dart.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dart.yml b/.github/workflows/dart.yml index c3e6bf9..8fa0543 100644 --- a/.github/workflows/dart.yml +++ b/.github/workflows/dart.yml @@ -11,12 +11,10 @@ jobs: runs-on: ubuntu-latest - container: - image: dart:latest - steps: - uses: actions/checkout@v3 + - uses: dart-lang/setup-dart@v1 - name: Install dependencies - run: pub get + run: dart pub get - name: Run tests - run: pub run test + run: dart test