-
Notifications
You must be signed in to change notification settings - Fork 0
/
preheader.go
47 lines (36 loc) · 1008 Bytes
/
preheader.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
package ergo
/*
#include "ergo.h"
*/
import "C"
import "runtime"
// PreHeader represents a block header with the current SpendingTransaction, that can be predicted by a miner before its formation
type PreHeader interface {
// Equals checks if provided PreHeader is same
Equals(preHeader PreHeader) bool
pointer() C.PreHeaderPtr
}
type preHeader struct {
p C.PreHeaderPtr
}
func newPreHeader(h *preHeader) PreHeader {
runtime.SetFinalizer(h, finalizePreHeader)
return h
}
// NewPreHeader creates PreHeader using data from BlockHeader
func NewPreHeader(header BlockHeader) PreHeader {
var p C.PreHeaderPtr
C.ergo_lib_preheader_from_block_header(header.pointer(), &p)
ph := &preHeader{p: p}
return newPreHeader(ph)
}
func (h *preHeader) Equals(preHeader PreHeader) bool {
res := C.ergo_lib_pre_header_eq(h.p, preHeader.pointer())
return bool(res)
}
func (h *preHeader) pointer() C.PreHeaderPtr {
return h.p
}
func finalizePreHeader(h *preHeader) {
C.ergo_lib_preheader_delete(h.p)
}