forked from vsc-eco/hivego
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransaction.go
More file actions
83 lines (68 loc) · 1.99 KB
/
Copy pathtransaction.go
File metadata and controls
83 lines (68 loc) · 1.99 KB
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
package hivego
import (
"encoding/hex"
"github.com/decred/dcrd/dcrec/secp256k1/v2"
"github.com/vsc-eco/hivego/utils"
)
type HiveTransaction struct {
RefBlockNum uint16 `json:"ref_block_num"`
RefBlockPrefix uint32 `json:"ref_block_prefix"`
Expiration string `json:"expiration"`
Operations []HiveOperation `json:"-"`
OperationsJs [][2]interface{} `json:"operations"`
Extensions []string `json:"extensions"`
Signatures []string `json:"signatures"`
}
func (t *HiveTransaction) GenerateTrxId() (string, error) {
tB, err := SerializeTx(*t)
if err != nil {
return "", err
}
digest := HashTx(tB)
return hex.EncodeToString(digest)[0:40], nil
}
func (t *HiveTransaction) Sign(keyPair KeyPair) (string, error) {
message, err := SerializeTx(*t)
if err != nil {
return "", err
}
digest := HashTxForSig(message)
sig, err := secp256k1.SignCompact(keyPair.PrivateKey, digest, true)
if err != nil {
return "", err
}
return hex.EncodeToString(sig), nil
}
func (t *HiveTransaction) AddSig(sig string) {
t.Signatures = append(t.Signatures, sig)
}
func (t *HiveTransaction) prepareJson() {
var opsContainer [][2]interface{}
for _, op := range t.Operations {
var opContainer [2]interface{}
opContainer[0] = op.OpName()
opContainer[1] = op
opsContainer = append(opsContainer, opContainer)
}
if t.Extensions == nil {
t.Extensions = []string{}
}
t.OperationsJs = opsContainer
}
type TransactionQueryParams struct {
TransactionId string `json:"id"`
IncludeReversible bool `json:"include_reversible"`
}
func (h *HiveRpcNode) GetTransaction(txId string, includeReversible bool) (HiveTransaction, error) {
var ht HiveTransaction
q := hrpcQuery{method: CondenserApiGetTransaction, params: TransactionQueryParams{TransactionId: txId, IncludeReversible: includeReversible}}
res, err := h.CallRaw(q)
if err != nil {
return ht, err
}
err = utils.Recast(res.Result, &ht)
if err != nil {
return ht, err
}
return ht, nil
}