forked from vulpemventures/go-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
block.go
112 lines (96 loc) · 2.59 KB
/
block.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package block
import (
"bytes"
"encoding/hex"
"github.com/yenkuanlee/go-elements/transaction"
)
const (
null = iota
compact
full
hashSize = 32
DYNAFED_HF_MASK = uint32(1 << 31)
)
type Block struct {
Header *Header
TransactionsData *Transactions
}
type Transactions struct {
Transactions []*transaction.Transaction
}
func NewFromBuffer(buf *bytes.Buffer) (*Block, error) {
return deserialize(buf)
}
func NewFromHex(h string) (*Block, error) {
hexBytes, err := hex.DecodeString(h)
if err != nil {
return nil, err
}
buf := bytes.NewBuffer(hexBytes)
return NewFromBuffer(buf)
}
type Header struct {
// Version - should be 0x20000000 except when versionbits signalling
Version uint32
// Previous blockhash
PrevBlockHash []byte
// Transaction Merkle root
MerkleRoot []byte
// Block timestamp
Timestamp uint32
// Block Height
Height uint32
// Block signature and dynamic federation-related data
ExtData *ExtData
}
// ExtData block signature and dynamic federation-related data
type ExtData struct {
// Liquid v1-style static `signblockscript` and witness
Proof *Proof
// Dynamic federations
DynamicFederation *DynamicFederation
// is dynamic federation
IsDyna bool
}
// Proof Liquid v1-style static `signblockscript` and witness
type Proof struct {
// Block "public key"
Challenge []byte
// Satisfying witness to the above Challenge, or nothing
Solution []byte
}
type DynamicFederation struct {
Current *DynamicFederationParams
Proposed *DynamicFederationParams
SignBlockWitness [][]byte
}
type DynamicFederationParams struct {
CompactParams *CompactParams
FullParams *FullParams
}
// CompactParams params where the fedpeg data and extension space
// are not included, and are assumed to be equal to the values
// from the previous block
type CompactParams struct {
// "scriptPubKey" used for block signing
SignBlockScript []byte
/// Maximum, in bytes, of the size of a blocksigning witness
SignBlockWitnessLimit uint32
/// Merkle root of extra data
ElidedRoot []byte
}
// FullParams full dynamic federations parameters
type FullParams struct {
// "scriptPubKey" used for block signing
SignBlockScript []byte
// Maximum, in bytes, of the size of a blocksigning witness
SignBlockWitnessLimit uint32
// Untweaked `scriptPubKey` used for pegins
FedpegProgram []byte
// For v0 fedpeg programs, the witness script of the untweaked
// pegin address. For future versions, this data has no defined
// meaning and will be considered "anyone can spend".
FedpegScript []byte
/// "Extension space" used by Liquid for PAK key entries
ExtensionSpace [][]byte
}