Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cake update v15 #2

Open
wants to merge 8 commits into
base: cake-update-v9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 38 additions & 62 deletions example/lib/global/old_examples/bitcoin_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import 'package:bitcoin_base/bitcoin_base.dart';
import 'package:blockchain_utils/blockchain_utils.dart';
import 'package:example/services_examples/explorer_service/explorer_service.dart';

/// Calculates the change value based on the sum of all provided values.
///
Expand All @@ -19,8 +18,7 @@ import 'package:example/services_examples/explorer_service/explorer_service.dart
/// Returns:
/// - The change value.
BigInt _changeValue(BigInt sum, List<BigInt> all) {
final sumAll = all.fold<BigInt>(
BigInt.zero, (previousValue, element) => previousValue + element);
final sumAll = all.fold<BigInt>(BigInt.zero, (previousValue, element) => previousValue + element);

final remind = sum - sumAll;
if (remind < BigInt.zero) {
Expand Down Expand Up @@ -61,27 +59,25 @@ void _spendFromP2pkhTo10DifferentType() async {
final examplePublicKey2 = examplePrivateKey.getPublic();

/// Define transaction outputs
final out1 = P2pkhAddress.fromAddress(
address: "msxiCJXD2WB43wK2PpTUvoqQLF7ZP98qqM", network: network);
final out1 =
P2pkhAddress.fromAddress(address: "msxiCJXD2WB43wK2PpTUvoqQLF7ZP98qqM", network: network);
final out2 = P2trAddress.fromAddress(
address: "tb1plq65drqavf93wf63d8g7d8ypuzaargd5h9d35u05ktrcwxq4a6ss0gpvrt",
network: network);
address: "tb1plq65drqavf93wf63d8g7d8ypuzaargd5h9d35u05ktrcwxq4a6ss0gpvrt", network: network);
final out3 = P2wpkhAddress.fromAddress(
address: "tb1q3zqgu9j368wgk8u5f9vtmkdwq8geetdxry690d", network: network);
final out4 = P2pkAddress.fromPubkey(pubkey: examplePublicKey.publicKey.toHex());
final out5 = P2shAddress.fromAddress(
address: "2N5hVdETdJMwLDxxttfqeWgMuny6K4SYGSc", network: network);
final out6 = P2shAddress.fromAddress(
address: "2NDAUpeUB1kGAQET8SojF8seXNrk3uudtCb", network: network);
final out7 = P2shAddress.fromAddress(
address: "2NE9CYdxju2iEAfR4FMdKPUcZbnKcfCiLhM", network: network);
final out8 = P2shAddress.fromAddress(
address: "2MwGRf8wNJsaYKdigqPwikPpg9JAT2faaPB", network: network);
final out4 = P2pkAddress.fromPubkey(pubkey: ECPublic.fromBip32(examplePublicKey.publicKey));
final out5 =
P2shAddress.fromAddress(address: "2N5hVdETdJMwLDxxttfqeWgMuny6K4SYGSc", network: network);
final out6 =
P2shAddress.fromAddress(address: "2NDAUpeUB1kGAQET8SojF8seXNrk3uudtCb", network: network);
final out7 =
P2shAddress.fromAddress(address: "2NE9CYdxju2iEAfR4FMdKPUcZbnKcfCiLhM", network: network);
final out8 =
P2shAddress.fromAddress(address: "2MwGRf8wNJsaYKdigqPwikPpg9JAT2faaPB", network: network);
final out9 = P2wshAddress.fromAddress(
address: "tb1qes3upam2nv3rc6s38tqgk0cqh6dlycvk6cjydyvpx9zlumh4h4lsjq26p8",
network: network);
final out10 = P2shAddress.fromAddress(
address: "2N2aRKjTQ3uzgUSLWFQAUDvKLnKCiBfCSAh", network: network);
address: "tb1qes3upam2nv3rc6s38tqgk0cqh6dlycvk6cjydyvpx9zlumh4h4lsjq26p8", network: network);
final out10 =
P2shAddress.fromAddress(address: "2N2aRKjTQ3uzgUSLWFQAUDvKLnKCiBfCSAh", network: network);

/// Calculate the change value for the transaction
final change = _changeValue(
Expand Down Expand Up @@ -130,8 +126,7 @@ void _spendFromP2pkhTo10DifferentType() async {
/// Create a UTXO using a BitcoinUtxo with specific details
utxo: BitcoinUtxo(
/// Transaction hash uniquely identifies the referenced transaction
txHash:
"b06f4ed0b49a5092a9ea206553ddc5fc469be694d0d28c95598c653e66cdeb5e",
txHash: "b06f4ed0b49a5092a9ea206553ddc5fc469be694d0d28c95598c653e66cdeb5e",

/// Value represents the amount of the UTXO in satoshis.
value: BigInt.from(250000),
Expand All @@ -145,19 +140,16 @@ void _spendFromP2pkhTo10DifferentType() async {

/// Include owner details with the public key and address associated with the UTXO
ownerDetails: UtxoAddressDetails(
publicKey: examplePublicKey2.toHex(),
address: examplePublicKey2.toP2pkhAddress())),
publicKey: examplePublicKey2.toHex(), address: examplePublicKey2.toP2pkhAddress())),
UtxoWithAddress(
utxo: BitcoinUtxo(
txHash:
"6ff0bdb2966f62f5e202c924e1cab1368b0258833e48986cc0a70fbca624ba93",
txHash: "6ff0bdb2966f62f5e202c924e1cab1368b0258833e48986cc0a70fbca624ba93",
value: BigInt.from(812830),
vout: 0,
scriptType: examplePublicKey2.toP2pkhAddress().type,
),
ownerDetails: UtxoAddressDetails(
publicKey: examplePublicKey2.toHex(),
address: examplePublicKey2.toP2pkhAddress())),
publicKey: examplePublicKey2.toHex(), address: examplePublicKey2.toP2pkhAddress())),
]);

/// Build the transaction by invoking the buildTransaction method on the BitcoinTransactionBuilder
Expand Down Expand Up @@ -249,8 +241,8 @@ void _spendFrom10DifferentTypeToP2pkh() async {

/// outputs
/// make sure pass network to address for validate, before sending create transaction
final out1 = P2pkhAddress.fromAddress(
address: "n4bkvTyU1dVdzsrhWBqBw8fEMbHjJvtmJR", network: network);
final out1 =
P2pkhAddress.fromAddress(address: "n4bkvTyU1dVdzsrhWBqBw8fEMbHjJvtmJR", network: network);

final builder = BitcoinTransactionBuilder(

Expand All @@ -272,8 +264,7 @@ void _spendFrom10DifferentTypeToP2pkh() async {
UtxoWithAddress(
utxo: BitcoinUtxo(
/// Transaction hash uniquely identifies the referenced transaction
txHash:
"05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
txHash: "05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",

/// Value represents the amount of the UTXO in satoshis.
value: BtcUtils.toSatoshi("0.001"),
Expand All @@ -291,8 +282,7 @@ void _spendFrom10DifferentTypeToP2pkh() async {
address: childKey1PublicKey.toP2pkhAddress())),
UtxoWithAddress(
utxo: BitcoinUtxo(
txHash:
"05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
txHash: "05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
value: BtcUtils.toSatoshi("0.001"),
vout: 1,
scriptType: childKey1PublicKey.toTaprootAddress().type,
Expand All @@ -302,8 +292,7 @@ void _spendFrom10DifferentTypeToP2pkh() async {
address: childKey1PublicKey.toTaprootAddress())),
UtxoWithAddress(
utxo: BitcoinUtxo(
txHash:
"05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
txHash: "05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
value: BtcUtils.toSatoshi("0.001"),
vout: 2,
scriptType: childKey1PublicKey.toP2wpkhAddress().type,
Expand All @@ -313,53 +302,44 @@ void _spendFrom10DifferentTypeToP2pkh() async {
address: childKey1PublicKey.toP2wpkhAddress())),
UtxoWithAddress(
utxo: BitcoinUtxo(
txHash:
"05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
txHash: "05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
value: BtcUtils.toSatoshi("0.001"),
vout: 3,
scriptType: examplePublicKey.toP2pkAddress().type,
),
ownerDetails: UtxoAddressDetails(
publicKey: examplePublicKey.toHex(),
address: examplePublicKey.toP2pkAddress())),
publicKey: examplePublicKey.toHex(), address: examplePublicKey.toP2pkAddress())),
UtxoWithAddress(
utxo: BitcoinUtxo(
txHash:
"05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
txHash: "05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
value: BtcUtils.toSatoshi("0.001"),
vout: 4,
scriptType: examplePublicKey.toP2pkInP2sh().type,
),
ownerDetails: UtxoAddressDetails(
publicKey: examplePublicKey.toHex(),
address: examplePublicKey.toP2pkInP2sh())),
publicKey: examplePublicKey.toHex(), address: examplePublicKey.toP2pkInP2sh())),
UtxoWithAddress(
utxo: BitcoinUtxo(
txHash:
"05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
txHash: "05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
value: BtcUtils.toSatoshi("0.001"),
vout: 5,
scriptType: examplePublicKey.toP2pkhInP2sh().type,
),
ownerDetails: UtxoAddressDetails(
publicKey: examplePublicKey.toHex(),
address: examplePublicKey.toP2pkhInP2sh())),
publicKey: examplePublicKey.toHex(), address: examplePublicKey.toP2pkhInP2sh())),
UtxoWithAddress(
utxo: BitcoinUtxo(
txHash:
"05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
txHash: "05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
value: BtcUtils.toSatoshi("0.001"),
vout: 6,
scriptType: examplePublicKey.toP2wpkhInP2sh().type,
blockHeight: 0,
),
ownerDetails: UtxoAddressDetails(
publicKey: examplePublicKey.toHex(),
address: examplePublicKey.toP2wpkhInP2sh())),
publicKey: examplePublicKey.toHex(), address: examplePublicKey.toP2wpkhInP2sh())),
UtxoWithAddress(
utxo: BitcoinUtxo(
txHash:
"05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
txHash: "05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
value: BtcUtils.toSatoshi("0.001"),
vout: 7,
scriptType: msig.toP2shAddress().type,
Expand All @@ -371,28 +351,24 @@ void _spendFrom10DifferentTypeToP2pkh() async {
multiSigAddress: msig, address: msig.toP2shAddress())),
UtxoWithAddress(
utxo: BitcoinUtxo(
txHash:
"05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
txHash: "05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
value: BtcUtils.toSatoshi("0.001"),
vout: 8,
scriptType: msig.toP2wshAddress(network: network).type,
blockHeight: 0,
),
ownerDetails: UtxoAddressDetails.multiSigAddress(
multiSigAddress: msig,
address: msig.toP2wshAddress(network: network))),
multiSigAddress: msig, address: msig.toP2wshAddress(network: network))),
UtxoWithAddress(
utxo: BitcoinUtxo(
txHash:
"05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
txHash: "05411dce1a1c9e3f44b54413bdf71e7ab3eff1e2f94818a3568c39814c27b258",
value: BtcUtils.toSatoshi("0.0015783"),
vout: 9,
scriptType: msig2.toP2wshInP2shAddress(network: network).type,
blockHeight: 0,
),
ownerDetails: UtxoAddressDetails.multiSigAddress(
multiSigAddress: msig2,
address: msig2.toP2wshInP2shAddress(network: network))),
multiSigAddress: msig2, address: msig2.toP2wshInP2shAddress(network: network))),
]);

/// Build the transaction by invoking the buildTransaction method on the BitcoinTransactionBuilder
Expand Down
Loading