@@ -8,9 +8,12 @@ abstract class BitcoinAddressType implements Enumerate {
88
99 /// Factory method to create a BitcoinAddressType enum value from a name or value.
1010 static BitcoinAddressType fromValue (String ? value) {
11- return values.firstWhere ((element) => element.value == value,
12- orElse: () =>
13- throw DartBitcoinPluginException ('Unknown address type. $value ' ));
11+ return values.firstWhere (
12+ (element) => element.value == value,
13+ orElse:
14+ () =>
15+ throw DartBitcoinPluginException ('Unknown address type. $value ' ),
16+ );
1417 }
1518
1619 /// Check if the address type is Pay-to-Script-Hash (P2SH).
@@ -21,11 +24,11 @@ abstract class BitcoinAddressType implements Enumerate {
2124 bool get isP2sh32 => isP2sh && hashLength == 32 ;
2225
2326 bool get supportBip137 => switch (this ) {
24- P2pkhAddressType .p2pkh || P2pkhAddressType .p2pkhwt => true ,
25- P2shAddressType .p2wpkhInP2sh => true ,
26- SegwitAddressType .p2wpkh => true ,
27- _ => false
28- };
27+ P2pkhAddressType .p2pkh || P2pkhAddressType .p2pkhwt => true ,
28+ P2shAddressType .p2wpkhInP2sh => true ,
29+ SegwitAddressType .p2wpkh => true ,
30+ _ => false ,
31+ };
2932
3033 // Enum values as a list for iteration
3134 static const List <BitcoinAddressType > values = [
@@ -43,13 +46,14 @@ abstract class BitcoinAddressType implements Enumerate {
4346 P2shAddressType .p2pkInP2sh32wt,
4447 P2shAddressType .p2pkhInP2shwt,
4548 P2shAddressType .p2pkInP2shwt,
46- P2pkhAddressType .p2pkhwt
49+ P2pkhAddressType .p2pkhwt,
4750 ];
4851 T cast <T extends BitcoinAddressType >() {
4952 if (this is ! T ) {
5053 throw DartBitcoinPluginException (
51- "Invalid cast: expected ${T .runtimeType }, but found $runtimeType ." ,
52- details: {'expected' : '$T ' , 'type' : value});
54+ "Invalid cast: expected ${T .runtimeType }, but found $runtimeType ." ,
55+ details: {'expected' : '$T ' , 'type' : value},
56+ );
5357 }
5458 return this as T ;
5559 }
@@ -62,23 +66,29 @@ abstract class BitcoinAddressType implements Enumerate {
6266
6367abstract class BitcoinBaseAddress {
6468 const BitcoinBaseAddress ();
65- factory BitcoinBaseAddress .fromProgram (
66- {required String addressProgram, required BitcoinAddressType type}) {
69+ factory BitcoinBaseAddress .fromProgram ({
70+ required String addressProgram,
71+ required BitcoinAddressType type,
72+ }) {
6773 if (type.isP2sh) {
6874 return P2shAddress .fromHash160 (
69- addrHash: addressProgram, type: type.cast ());
75+ addrHash: addressProgram,
76+ type: type.cast (),
77+ );
7078 }
7179 return switch (type) {
7280 PubKeyAddressType .p2pk => P2pkAddress (publicKey: addressProgram),
73- P2pkhAddressType .p2pkh ||
74- P2pkhAddressType .p2pkhwt =>
81+ P2pkhAddressType .p2pkh || P2pkhAddressType .p2pkhwt =>
7582 P2pkhAddress .fromHash160 (addrHash: addressProgram, type: type.cast ()),
76- SegwitAddressType .p2wpkh =>
77- P2wpkhAddress .fromProgram (program: addressProgram),
78- SegwitAddressType .p2wsh =>
79- P2wshAddress .fromProgram (program: addressProgram),
80- SegwitAddressType .p2tr =>
81- P2trAddress .fromProgram (program: addressProgram),
83+ SegwitAddressType .p2wpkh => P2wpkhAddress .fromProgram (
84+ program: addressProgram,
85+ ),
86+ SegwitAddressType .p2wsh => P2wshAddress .fromProgram (
87+ program: addressProgram,
88+ ),
89+ SegwitAddressType .p2tr => P2trAddress .fromProgram (
90+ program: addressProgram,
91+ ),
8292 _ => throw DartBitcoinPluginException ("Unsuported bitcoin address type." ),
8393 };
8494 }
@@ -125,15 +135,27 @@ class P2pkhAddressType extends BitcoinAddressType {
125135
126136class P2shAddressType extends BitcoinAddressType {
127137 const P2shAddressType ._(super .value, this .hashLength, this .withToken)
128- : super ._();
138+ : super ._();
129139 static const P2shAddressType p2wshInP2sh = P2shAddressType ._(
130- 'P2SH/P2WSH' , _BitcoinAddressUtils .hash160DigestLength, false );
140+ 'P2SH/P2WSH' ,
141+ BitcoinAddressUtils .hash160DigestLength,
142+ false ,
143+ );
131144 static const P2shAddressType p2wpkhInP2sh = P2shAddressType ._(
132- 'P2SH/P2WPKH' , _BitcoinAddressUtils .hash160DigestLength, false );
145+ 'P2SH/P2WPKH' ,
146+ BitcoinAddressUtils .hash160DigestLength,
147+ false ,
148+ );
133149 static const P2shAddressType p2pkhInP2sh = P2shAddressType ._(
134- 'P2SH/P2PKH' , _BitcoinAddressUtils .hash160DigestLength, false );
150+ 'P2SH/P2PKH' ,
151+ BitcoinAddressUtils .hash160DigestLength,
152+ false ,
153+ );
135154 static const P2shAddressType p2pkInP2sh = P2shAddressType ._(
136- 'P2SH/P2PK' , _BitcoinAddressUtils .hash160DigestLength, false );
155+ 'P2SH/P2PK' ,
156+ BitcoinAddressUtils .hash160DigestLength,
157+ false ,
158+ );
137159 @override
138160 bool get isP2sh => true ;
139161 @override
@@ -146,26 +168,44 @@ class P2shAddressType extends BitcoinAddressType {
146168 /// specify BCH NETWORK for now!
147169 /// Pay-to-Script-Hash-32
148170 static const P2shAddressType p2pkhInP2sh32 = P2shAddressType ._(
149- 'P2SH32/P2PKH' , _BitcoinAddressUtils .scriptHashLenght, false );
171+ 'P2SH32/P2PKH' ,
172+ BitcoinAddressUtils .scriptHashLenght,
173+ false ,
174+ );
150175 //// Pay-to-Script-Hash-32
151176 static const P2shAddressType p2pkInP2sh32 = P2shAddressType ._(
152- 'P2SH32/P2PK' , _BitcoinAddressUtils .scriptHashLenght, false );
177+ 'P2SH32/P2PK' ,
178+ BitcoinAddressUtils .scriptHashLenght,
179+ false ,
180+ );
153181
154182 /// Pay-to-Script-Hash-32-with-token
155183 static const P2shAddressType p2pkhInP2sh32wt = P2shAddressType ._(
156- 'P2SH32WT/P2PKH' , _BitcoinAddressUtils .scriptHashLenght, true );
184+ 'P2SH32WT/P2PKH' ,
185+ BitcoinAddressUtils .scriptHashLenght,
186+ true ,
187+ );
157188
158189 /// Pay-to-Script-Hash-32-with-token
159190 static const P2shAddressType p2pkInP2sh32wt = P2shAddressType ._(
160- 'P2SH32WT/P2PK' , _BitcoinAddressUtils .scriptHashLenght, true );
191+ 'P2SH32WT/P2PK' ,
192+ BitcoinAddressUtils .scriptHashLenght,
193+ true ,
194+ );
161195
162196 /// Pay-to-Script-Hash-with-token
163197 static const P2shAddressType p2pkhInP2shwt = P2shAddressType ._(
164- 'P2SHWT/P2PKH' , _BitcoinAddressUtils .hash160DigestLength, true );
198+ 'P2SHWT/P2PKH' ,
199+ BitcoinAddressUtils .hash160DigestLength,
200+ true ,
201+ );
165202
166203 /// Pay-to-Script-Hash-with-token
167204 static const P2shAddressType p2pkInP2shwt = P2shAddressType ._(
168- 'P2SHWT/P2PK' , _BitcoinAddressUtils .hash160DigestLength, true );
205+ 'P2SHWT/P2PK' ,
206+ BitcoinAddressUtils .hash160DigestLength,
207+ true ,
208+ );
169209
170210 @override
171211 String toString () {
0 commit comments