-
Notifications
You must be signed in to change notification settings - Fork 14
/
address_p2sh.go
48 lines (39 loc) · 1.16 KB
/
address_p2sh.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// tokucore
//
// Copyright 2019 by KeyFuse Labs
// BSD License
package xcore
import (
"github.com/keyfuse/tokucore/network"
"github.com/keyfuse/tokucore/xbase"
)
// *******************************************
// PayToScriptHashAddress(P2SH)
// *******************************************
// PayToScriptHashAddress --
type PayToScriptHashAddress struct {
scriptHash [20]byte
}
// NewPayToScriptHashAddress -- creates a new PayToScriptHashAddress.
func NewPayToScriptHashAddress(hash160 []byte) Address {
if len(hash160) != 20 {
return nil
}
var hash [20]byte
copy(hash[:], hash160)
return &PayToScriptHashAddress{
scriptHash: hash,
}
}
// ToString -- the implementation method for xcore.Address interface.
func (a *PayToScriptHashAddress) ToString(net *network.Network) string {
return xbase.Base58CheckEncode(a.scriptHash[:], net.ScriptHashAddrID)
}
// Hash160 -- returns the address hash160 bytes>
func (a *PayToScriptHashAddress) Hash160() []byte {
return a.scriptHash[:]
}
// LockingScript -- the address locking script.
func (a *PayToScriptHashAddress) LockingScript() ([]byte, error) {
return NewPayToScriptHashScript(a.Hash160()).GetRawLockingScriptBytes()
}