/
TXOutput.go
42 lines (28 loc) · 931 Bytes
/
TXOutput.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
package BLC
import (
"bytes"
)
type TXOutput struct {
//面值
Value int64
//用户名
Ripemd160Hash []byte //用户名 公钥两次哈希后的值
}
func NewTXOutput(value int64,address string) *TXOutput {
txOutput := &TXOutput{value,nil}
// 设置Ripemd160Hash
txOutput.Lock(address)
return txOutput
}
//锁定
func (txOutput *TXOutput) Lock(address string) {
version_pubKeyHash_checkSumBytes := Base58Decode([]byte(address))
txOutput.Ripemd160Hash = version_pubKeyHash_checkSumBytes[1:len(version_pubKeyHash_checkSumBytes)-4]
}
//解锁
func (txOutput *TXOutput) UnLockScriptPubKeyWithAddress(address string) bool {
version_pubKeyHash_checkSumBytes := Base58Decode([]byte(address))
ripemd160Hash := version_pubKeyHash_checkSumBytes[1:len(version_pubKeyHash_checkSumBytes) - 4]
//fmt.Println(txOutput.Ripemd160Hash, ripemd160Hash)
return bytes.Compare(txOutput.Ripemd160Hash, ripemd160Hash) == 0
}