Skip to content

Commit

Permalink
Merge branch 'dart_v2_final'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnetwork committed Dec 4, 2024
2 parents f451e9c + 76deefa commit 7fbb468
Show file tree
Hide file tree
Showing 22 changed files with 196 additions and 121 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## 4.9.2
## 4.9.4
* Improved serialization process for large transaction scripts.
* Added support for the Electra network.
* Create and spent from uncomprossed public key format.
* Important Notice: This is the final version supporting Dart v2. The next release will require Dart v3.3 or higher.


## 4.9.2
* Update dependencies
* Resolved issue with transaction deserialization (unsigned tx)

Expand Down
10 changes: 4 additions & 6 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# include: package:lints/recommended.yaml
include: package:flutter_lints/flutter.yaml
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
# Uncomment the following section to specify additional rules.
linter:
rules:
- unnecessary_const
- prefer_const_declarations
- prefer_final_locals # Warns when a local variable could be final
- prefer_final_in_for_each # Warns when a forEach variable could be final
prefer_final_locals: true # Warns when a local variable could be final
prefer_final_in_for_each: true # Warns when a forEach variable could be final
prefer_const_constructors: true # Warns when a constructor could be const
prefer_const_declarations: true # Warns when a declaration could be const
11 changes: 6 additions & 5 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ packages:
path: ".."
relative: true
source: path
version: "4.9.2"
version: "4.9.4"
blockchain_utils:
dependency: "direct main"
description:
path: "../../blockchain_utils"
relative: true
source: path
version: "3.5.0"
name: blockchain_utils
sha256: "1e4f30b98d92f7ccf2eda009a23b53871a1c9b8b6dfa00bb1eb17ec00ae5eeeb"
url: "https://pub.dev"
source: hosted
version: "3.6.0"
boolean_selector:
dependency: transitive
description:
Expand Down
6 changes: 3 additions & 3 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ dependencies:
cupertino_icons: ^1.0.2
bitcoin_base:
path: ../
blockchain_utils:
path: ../../../blockchain_utils
# blockchain_utils: ^3.5.0
# blockchain_utils:
# path: ../../blockchain_utils
blockchain_utils: ^3.6.0
http: ^1.2.0

dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion lib/bitcoin_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/// including spending transactions, Bitcoin address management,
/// Bitcoin Schnorr signatures, BIP-39 mnemonic phrase generation,
/// hierarchical deterministic (HD) wallet derivation, and Web3 Secret Storage Definition.
library;
library bitcoin_base;

export 'package:bitcoin_base/src/bitcoin/address/address.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/src/bitcoin/address/address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// - Utility functions for address manipulation.
// - encode/decode Segregated Witness (SegWit) address implementation.
// - Enhanced functionality for improved handling of addresses across diverse networks.
library;
library address;

import 'package:bitcoin_base/bitcoin_base.dart';
import 'package:bitcoin_base/src/exception/exception.dart';
Expand Down
28 changes: 14 additions & 14 deletions lib/src/bitcoin/address/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ abstract class BitcoinAddressType implements Enumerate {
// Enum values as a list for iteration
static const List<BitcoinAddressType> values = [
P2pkhAddressType.p2pkh,
SegwitAddresType.p2wpkh,
SegwitAddresType.p2tr,
SegwitAddresType.p2wsh,
SegwitAddressType.p2wpkh,
SegwitAddressType.p2tr,
SegwitAddressType.p2wsh,
P2shAddressType.p2wshInP2sh,
P2shAddressType.p2wpkhInP2sh,
P2shAddressType.p2pkhInP2sh,
Expand Down Expand Up @@ -59,7 +59,7 @@ abstract class BitcoinBaseAddress {
}

class PubKeyAddressType extends BitcoinAddressType {
const PubKeyAddressType._(super.value) : super._();
const PubKeyAddressType._(String value) : super._(value);
static const PubKeyAddressType p2pk = PubKeyAddressType._("P2PK");
@override
bool get isP2sh => false;
Expand All @@ -75,7 +75,7 @@ class PubKeyAddressType extends BitcoinAddressType {
}

class P2pkhAddressType extends BitcoinAddressType {
const P2pkhAddressType._(super.value) : super._();
const P2pkhAddressType._(String value) : super._(value);
static const P2pkhAddressType p2pkh = P2pkhAddressType._("P2PKH");
static const P2pkhAddressType p2pkhwt = P2pkhAddressType._("P2PKHWT");

Expand All @@ -93,8 +93,8 @@ class P2pkhAddressType extends BitcoinAddressType {
}

class P2shAddressType extends BitcoinAddressType {
const P2shAddressType._(super.value, this.hashLength, this.withToken)
: super._();
const P2shAddressType._(String value, this.hashLength, this.withToken)
: super._(value);
static const P2shAddressType p2wshInP2sh = P2shAddressType._(
"P2SH/P2WSH", _BitcoinAddressUtils.hash160DigestLength, false);
static const P2shAddressType p2wpkhInP2sh = P2shAddressType._(
Expand Down Expand Up @@ -142,11 +142,11 @@ class P2shAddressType extends BitcoinAddressType {
}
}

class SegwitAddresType extends BitcoinAddressType {
const SegwitAddresType._(super.value) : super._();
static const SegwitAddresType p2wpkh = SegwitAddresType._("P2WPKH");
static const SegwitAddresType p2tr = SegwitAddresType._("P2TR");
static const SegwitAddresType p2wsh = SegwitAddresType._("P2WSH");
class SegwitAddressType extends BitcoinAddressType {
const SegwitAddressType._(String value) : super._(value);
static const SegwitAddressType p2wpkh = SegwitAddressType._("P2WPKH");
static const SegwitAddressType p2tr = SegwitAddressType._("P2TR");
static const SegwitAddressType p2wsh = SegwitAddressType._("P2WSH");
@override
bool get isP2sh => false;
@override
Expand All @@ -155,7 +155,7 @@ class SegwitAddresType extends BitcoinAddressType {
@override
int get hashLength {
switch (this) {
case SegwitAddresType.p2wpkh:
case SegwitAddressType.p2wpkh:
return 20;
default:
return 32;
Expand All @@ -164,6 +164,6 @@ class SegwitAddresType extends BitcoinAddressType {

@override
String toString() {
return "SegwitAddresType.$value";
return "SegwitAddressType.$value";
}
}
20 changes: 10 additions & 10 deletions lib/src/bitcoin/address/legacy_address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ abstract class LegacyAddress implements BitcoinBaseAddress {

class P2shAddress extends LegacyAddress {
P2shAddress.fromScript(
{required super.script, this.type = P2shAddressType.p2pkInP2sh})
: super.fromScript();
{required Script script, this.type = P2shAddressType.p2pkInP2sh})
: super.fromScript(script: script);

P2shAddress.fromAddress(
{required super.address,
required super.network,
{required String address,
required BasedUtxoNetwork network,
this.type = P2shAddressType.p2pkInP2sh})
: super.fromAddress();
: super.fromAddress(address: address, network: network);
P2shAddress.fromHash160(
{required String addrHash, this.type = P2shAddressType.p2pkInP2sh})
: super.fromHash160(addrHash, type);
Expand Down Expand Up @@ -81,13 +81,13 @@ class P2shAddress extends LegacyAddress {

class P2pkhAddress extends LegacyAddress {
P2pkhAddress.fromScript(
{required super.script, this.type = P2pkhAddressType.p2pkh})
: super.fromScript();
{required Script script, this.type = P2pkhAddressType.p2pkh})
: super.fromScript(script: script);
P2pkhAddress.fromAddress(
{required super.address,
required super.network,
{required String address,
required BasedUtxoNetwork network,
this.type = P2pkhAddressType.p2pkh})
: super.fromAddress();
: super.fromAddress(address: address, network: network);
P2pkhAddress.fromHash160(
{required String addrHash, this.type = P2pkhAddressType.p2pkh})
: super.fromHash160(addrHash, type);
Expand Down
19 changes: 19 additions & 0 deletions lib/src/bitcoin/address/network_address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,22 @@ class BitcoinSVAddress extends BitcoinNetworkAddress<BitcoinSVNetwork> {
baseAddress, baseAddress.toAddress(network), network);
}
}

/// A concrete implementation of [BitcoinNetworkAddress] for Electra protocol network.
class ElectraProtocolAddress
extends BitcoinNetworkAddress<ElectraProtocolNetwork> {
const ElectraProtocolAddress._(BitcoinBaseAddress baseAddress, String address,
ElectraProtocolNetwork network)
: super._(address: address, baseAddress: baseAddress, network: network);
factory ElectraProtocolAddress(String address,
{ElectraProtocolNetwork network = ElectraProtocolNetwork.mainnet}) {
return ElectraProtocolAddress._(
_BitcoinAddressUtils.decodeAddress(address, network), address, network);
}
factory ElectraProtocolAddress.fromBaseAddress(BitcoinBaseAddress address,
{ElectraProtocolNetwork network = ElectraProtocolNetwork.mainnet}) {
final baseAddress = _BitcoinAddressUtils.validateAddress(address, network);
return ElectraProtocolAddress._(
baseAddress, baseAddress.toAddress(network), network);
}
}
62 changes: 40 additions & 22 deletions lib/src/bitcoin/address/segwit_address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class SegwitAddress implements BitcoinBaseAddress {
SegwitAddress.fromProgram(
{required String program,
required this.segwitVersion,
required SegwitAddresType addresType})
required SegwitAddressType addresType})
: addressProgram =
_BitcoinAddressUtils.validateAddressProgram(program, addresType);
SegwitAddress.fromScript(
Expand Down Expand Up @@ -46,15 +46,21 @@ abstract class SegwitAddress implements BitcoinBaseAddress {
}

class P2wpkhAddress extends SegwitAddress {
P2wpkhAddress.fromAddress({required super.address, required super.network})
: super.fromAddress(segwitVersion: _BitcoinAddressUtils.segwitV0);
P2wpkhAddress.fromAddress(
{required String address, required BasedUtxoNetwork network})
: super.fromAddress(
segwitVersion: _BitcoinAddressUtils.segwitV0,
address: address,
network: network);

P2wpkhAddress.fromProgram({required super.program})
P2wpkhAddress.fromProgram({required String program})
: super.fromProgram(
segwitVersion: _BitcoinAddressUtils.segwitV0,
addresType: SegwitAddresType.p2wpkh);
P2wpkhAddress.fromScript({required super.script})
: super.fromScript(segwitVersion: _BitcoinAddressUtils.segwitV0);
addresType: SegwitAddressType.p2wpkh,
program: program);
P2wpkhAddress.fromScript({required Script script})
: super.fromScript(
segwitVersion: _BitcoinAddressUtils.segwitV0, script: script);

/// returns the scriptPubKey of a P2WPKH witness script
@override
Expand All @@ -64,18 +70,24 @@ class P2wpkhAddress extends SegwitAddress {

/// returns the type of address
@override
SegwitAddresType get type => SegwitAddresType.p2wpkh;
SegwitAddressType get type => SegwitAddressType.p2wpkh;
}

class P2trAddress extends SegwitAddress {
P2trAddress.fromAddress({required super.address, required super.network})
: super.fromAddress(segwitVersion: _BitcoinAddressUtils.segwitV1);
P2trAddress.fromProgram({required super.program})
P2trAddress.fromAddress(
{required String address, required BasedUtxoNetwork network})
: super.fromAddress(
segwitVersion: _BitcoinAddressUtils.segwitV1,
address: address,
network: network);
P2trAddress.fromProgram({required String program})
: super.fromProgram(
segwitVersion: _BitcoinAddressUtils.segwitV1,
addresType: SegwitAddresType.p2tr);
P2trAddress.fromScript({required super.script})
: super.fromScript(segwitVersion: _BitcoinAddressUtils.segwitV1);
addresType: SegwitAddressType.p2tr,
program: program);
P2trAddress.fromScript({required Script script})
: super.fromScript(
segwitVersion: _BitcoinAddressUtils.segwitV1, script: script);

/// returns the scriptPubKey of a P2TR witness script
@override
Expand All @@ -85,18 +97,24 @@ class P2trAddress extends SegwitAddress {

/// returns the type of address
@override
SegwitAddresType get type => SegwitAddresType.p2tr;
SegwitAddressType get type => SegwitAddressType.p2tr;
}

class P2wshAddress extends SegwitAddress {
P2wshAddress.fromAddress({required super.address, required super.network})
: super.fromAddress(segwitVersion: _BitcoinAddressUtils.segwitV0);
P2wshAddress.fromProgram({required super.program})
P2wshAddress.fromAddress(
{required String address, required BasedUtxoNetwork network})
: super.fromAddress(
segwitVersion: _BitcoinAddressUtils.segwitV0,
address: address,
network: network);
P2wshAddress.fromProgram({required String program})
: super.fromProgram(
segwitVersion: _BitcoinAddressUtils.segwitV0,
addresType: SegwitAddresType.p2wsh);
P2wshAddress.fromScript({required super.script})
: super.fromScript(segwitVersion: _BitcoinAddressUtils.segwitV0);
addresType: SegwitAddressType.p2wsh,
program: program);
P2wshAddress.fromScript({required Script script})
: super.fromScript(
segwitVersion: _BitcoinAddressUtils.segwitV0, script: script);

/// Returns the scriptPubKey of a P2WPKH witness script
@override
Expand All @@ -106,5 +124,5 @@ class P2wshAddress extends SegwitAddress {

/// Returns the type of address
@override
SegwitAddresType get type => SegwitAddresType.p2wsh;
SegwitAddressType get type => SegwitAddressType.p2wsh;
}
2 changes: 1 addition & 1 deletion lib/src/bitcoin/address/utils/address_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class _BitcoinAddressUtils {
static BitcoinBaseAddress decodeAddress(
String address, BasedUtxoNetwork network) {
BitcoinBaseAddress? baseAddress;
if (network.supportedAddress.contains(SegwitAddresType.p2wpkh)) {
if (network.supportedAddress.contains(SegwitAddressType.p2wpkh)) {
baseAddress = toSegwitAddress(address, network);
}
baseAddress ??= toLegacy(address, network);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/bitcoin/script/op_code/constant_lib.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
library;
library op_code;

export 'constant.dart';
export 'tools.dart';
37 changes: 24 additions & 13 deletions lib/src/bitcoin_cash/bcmr_registery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -699,17 +699,26 @@ class ChainSnapshot extends IdentitySnapshot {
: null,
);
}
const ChainSnapshot({
required super.name,
required TokenCategory super.token,
super.description,
super.tags,
super.migrated,
super.status,
super.splitId,
super.uris,
super.extensions,
});
ChainSnapshot(
{required String name,
required String? description,
required List<String>? tags,
required String? migrated,
required TokenCategory token,
required String? status,
required String? splitId,
required URIs? uris,
required Extensions? extensions})
: super(
name: name,
description: description,
tags: tags,
migrated: migrated,
token: token,
status: status,
splitId: splitId,
uris: uris,
extensions: extensions);
}

class RegistryTimestampKeyedValues<T extends IdentitySnapshot> {
Expand All @@ -722,7 +731,8 @@ class RegistryTimestampKeyedValues<T extends IdentitySnapshot> {
}

class ChainHistory extends RegistryTimestampKeyedValues<ChainSnapshot> {
const ChainHistory({required super.timestampMap});
const ChainHistory({required Map<String, ChainSnapshot> timestampMap})
: super(timestampMap: timestampMap);

factory ChainHistory.fromJson(Map<String, dynamic> json) {
return ChainHistory(
Expand All @@ -734,7 +744,8 @@ class ChainHistory extends RegistryTimestampKeyedValues<ChainSnapshot> {
}

class IdentityHistory extends RegistryTimestampKeyedValues<IdentitySnapshot> {
const IdentityHistory({required super.timestampMap});
const IdentityHistory({required Map<String, IdentitySnapshot> timestampMap})
: super(timestampMap: timestampMap);

factory IdentityHistory.fromJson(Map<String, dynamic> json) {
return IdentityHistory(
Expand Down
Loading

0 comments on commit 7fbb468

Please sign in to comment.