@@ -17,17 +17,20 @@ var (
17
17
)
18
18
19
19
const (
20
- AddressTypeMainPKH = 0x00 // Public Key Hash (starts with 1)
21
- AddressTypeMainSH = 0x05 // Script Hash (starts with 3)
22
- AddressTypeMainMultiPKH = 0x76 // Multi-PKH (starts with p) - Experimental value. Not standard
23
- AddressTypeMainRPH = 0x7b // RPH (starts with r) - Experimental value. Not standard
24
- AddressTypeMainPK = 0x06 // Public Key - Experimental value. Not standard
25
-
26
- AddressTypeTestPKH = 0x6f // Testnet Public Key Hash (starts with m or n)
27
- AddressTypeTestSH = 0xc4 // Testnet Script Hash (starts with 2)
28
- AddressTypeTestMultiPKH = 0x78 // Multi-PKH (starts with q) - Experimental value. Not standard
29
- AddressTypeTestRPH = 0x7d // RPH (starts with s) - Experimental value. Not standard
30
- AddressTypeTestPK = 0x07 // Public Key - Experimental value. Not standard
20
+ AddressTypeMainPKH = 0x00 // Public Key Hash (starts with 1)
21
+ AddressTypeMainSH = 0x05 // Script Hash (starts with 3)
22
+ AddressTypeMainMultiPKH = 0x76 // Multi-PKH (starts with p) - Experimental value. Not standard
23
+ AddressTypeMainRPH = 0x7b // RPH (starts with r) - Experimental value. Not standard
24
+ AddressTypeMainPK = 0x06 // Public Key - Experimental value. Not standard
25
+ AddressTypeMainNonStandard = 0x08 // Unknown, but possibly spendable locking script
26
+
27
+ AddressTypeTestPKH = 0x6f // Testnet Public Key Hash (starts with m or n)
28
+ AddressTypeTestSH = 0xc4 // Testnet Script Hash (starts with 2)
29
+ AddressTypeTestMultiPKH = 0x78 // Multi-PKH (starts with q) - Experimental value. Not standard
30
+ AddressTypeTestRPH = 0x7d // RPH (starts with s) - Experimental value. Not standard
31
+ AddressTypeTestPK = 0x07 // Public Key - Experimental value. Not standard
32
+ AddressTypeTestNonStandard = 0x09 // Unknown, but possibly spendable locking script
33
+
31
34
)
32
35
33
36
type Address struct {
@@ -94,6 +97,8 @@ func (a *Address) decodeBytes(b []byte) error {
94
97
return nil
95
98
case AddressTypeMainRPH :
96
99
return a .SetRPH (b [1 :], MainNet )
100
+ case AddressTypeMainNonStandard :
101
+ return a .SetNonStandard (b [1 :], MainNet )
97
102
98
103
// TestNet
99
104
case AddressTypeTestPKH :
@@ -129,6 +134,8 @@ func (a *Address) decodeBytes(b []byte) error {
129
134
return nil
130
135
case AddressTypeTestRPH :
131
136
return a .SetRPH (b [1 :], TestNet )
137
+ case AddressTypeTestNonStandard :
138
+ return a .SetNonStandard (b [1 :], TestNet )
132
139
}
133
140
134
141
return ErrBadType
@@ -182,6 +189,12 @@ func NewAddressFromRawAddress(ra RawAddress, net Network) Address {
182
189
} else {
183
190
result .addressType = AddressTypeTestRPH
184
191
}
192
+ case ScriptTypeNonStandard :
193
+ if net == MainNet {
194
+ result .addressType = AddressTypeMainNonStandard
195
+ } else {
196
+ result .addressType = AddressTypeTestNonStandard
197
+ }
185
198
}
186
199
187
200
return result
@@ -351,6 +364,28 @@ func (a *Address) SetRPH(rph []byte, net Network) error {
351
364
return nil
352
365
}
353
366
367
+ /**************************************** Non-Standard ********************************************/
368
+
369
+ // NewAddressNonStandard creates an address from a script that is non-standard but possibly
370
+ // spendable.
371
+ func NewAddressNonStandard (script []byte , net Network ) (Address , error ) {
372
+ var result Address
373
+ err := result .SetNonStandard (script , net )
374
+ return result , err
375
+ }
376
+
377
+ // SetNonStandard sets the R Puzzle Hash and script type of the address.
378
+ func (a * Address ) SetNonStandard (script []byte , net Network ) error {
379
+ if net == MainNet {
380
+ a .addressType = AddressTypeMainNonStandard
381
+ } else {
382
+ a .addressType = AddressTypeTestNonStandard
383
+ }
384
+
385
+ a .data = script
386
+ return nil
387
+ }
388
+
354
389
/***************************************** Common *************************************************/
355
390
356
391
func (a Address ) Type () byte {
@@ -365,13 +400,8 @@ func (a Address) String() string {
365
400
// Network returns the network id for the address.
366
401
func (a Address ) Network () Network {
367
402
switch a .addressType {
368
- case AddressTypeMainPKH :
369
- fallthrough
370
- case AddressTypeMainSH :
371
- fallthrough
372
- case AddressTypeMainMultiPKH :
373
- fallthrough
374
- case AddressTypeMainRPH :
403
+ case AddressTypeMainPKH , AddressTypeMainSH , AddressTypeMainMultiPKH , AddressTypeMainRPH ,
404
+ AddressTypeMainNonStandard :
375
405
return MainNet
376
406
}
377
407
return TestNet
@@ -385,25 +415,11 @@ func (a Address) IsEmpty() bool {
385
415
// Hash returns the hash corresponding to the address.
386
416
func (a Address ) Hash () (* Hash20 , error ) {
387
417
switch a .addressType {
388
- case AddressTypeMainPKH :
389
- fallthrough
390
- case AddressTypeTestPKH :
391
- fallthrough
392
- case AddressTypeMainSH :
393
- fallthrough
394
- case AddressTypeTestSH :
395
- fallthrough
396
- case AddressTypeMainRPH :
397
- fallthrough
398
- case AddressTypeTestRPH :
418
+ case AddressTypeMainPKH , AddressTypeTestPKH , AddressTypeMainSH , AddressTypeTestSH ,
419
+ AddressTypeMainRPH , AddressTypeTestRPH :
399
420
return NewHash20 (a .data )
400
- case AddressTypeMainPK :
401
- fallthrough
402
- case AddressTypeTestPK :
403
- fallthrough
404
- case AddressTypeMainMultiPKH :
405
- fallthrough
406
- case AddressTypeTestMultiPKH :
421
+ case AddressTypeMainPK , AddressTypeTestPK , AddressTypeMainMultiPKH , AddressTypeTestMultiPKH ,
422
+ AddressTypeMainNonStandard , AddressTypeTestNonStandard :
407
423
return NewHash20 (Hash160 (a .data ))
408
424
}
409
425
return nil , ErrUnknownScriptTemplate
0 commit comments