forked from smallnest/steem-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathident_wif.go
More file actions
121 lines (112 loc) · 4.4 KB
/
ident_wif.go
File metadata and controls
121 lines (112 loc) · 4.4 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
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
113
114
115
116
117
118
119
120
121
package rpc
import (
"github.com/pkg/errors"
"github.com/smallnest/steem-api/encoding/wif"
"github.com/smallnest/steem-api/types"
)
var (
OpTypeKey = make(map[types.OpType][]string)
)
func init() {
OpTypeKey["vote"] = []string{"posting"}
OpTypeKey["comment"] = []string{"posting"}
OpTypeKey["transfer"] = []string{"active"}
OpTypeKey["transfer_to_vesting"] = []string{"active"}
OpTypeKey["withdraw_vesting"] = []string{"active"}
OpTypeKey["limit_order_create"] = []string{"active"}
OpTypeKey["limit_order_cancel"] = []string{"active"}
OpTypeKey["feed_publish"] = []string{"active"}
OpTypeKey["convert"] = []string{"active"}
OpTypeKey["account_create"] = []string{"active"}
OpTypeKey["account_update"] = []string{"active"}
OpTypeKey["witness_update"] = []string{"active"}
OpTypeKey["account_witness_vote"] = []string{"active"}
OpTypeKey["account_witness_proxy"] = []string{"active"}
OpTypeKey["pow"] = []string{"active"}
OpTypeKey["custom"] = []string{"active"}
OpTypeKey["report_over_production"] = []string{"posting"}
OpTypeKey["delete_comment"] = []string{"posting"}
OpTypeKey["custom_json"] = []string{"posting"}
OpTypeKey["comment_options"] = []string{"posting"}
OpTypeKey["set_withdraw_vesting_route"] = []string{"active"}
OpTypeKey["limit_order_create2"] = []string{"active"}
OpTypeKey["challenge_authority"] = []string{"posting"}
OpTypeKey["prove_authority"] = []string{"active"}
OpTypeKey["request_account_recovery"] = []string{"active"}
OpTypeKey["recover_account"] = []string{"owner"}
OpTypeKey["change_recovery_account"] = []string{"owner"}
OpTypeKey["escrow_transfer"] = []string{"active"}
OpTypeKey["escrow_dispute"] = []string{"active"}
OpTypeKey["escrow_release"] = []string{"active"}
OpTypeKey["pow2"] = []string{"active"}
OpTypeKey["escrow_approve"] = []string{"active"}
OpTypeKey["transfer_to_savings"] = []string{"active"}
OpTypeKey["transfer_from_savings"] = []string{"active"}
OpTypeKey["cancel_transfer_from_savings"] = []string{"active"}
OpTypeKey["custom_binary"] = []string{"posting"}
OpTypeKey["decline_voting_rights"] = []string{"owner"}
OpTypeKey["reset_account"] = []string{"active"}
OpTypeKey["set_reset_account"] = []string{"posting"}
OpTypeKey["claim_reward_balance"] = []string{"posting"}
OpTypeKey["delegate_vesting_shares"] = []string{"active"}
OpTypeKey["account_create_with_delegation"] = []string{"active"}
OpTypeKey["fill_convert_request"] = []string{"active"}
OpTypeKey["author_reward"] = []string{"posting"}
OpTypeKey["curation_reward"] = []string{"posting"}
OpTypeKey["comment_reward"] = []string{"posting"}
OpTypeKey["liquidity_reward"] = []string{"active"}
OpTypeKey["interest"] = []string{"active"}
OpTypeKey["fill_vesting_withdraw"] = []string{"active"}
OpTypeKey["fill_order"] = []string{"posting"}
OpTypeKey["shutdown_witness"] = []string{"posting"}
OpTypeKey["fill_transfer_from_savings"] = []string{"posting"}
OpTypeKey["hardfork"] = []string{"posting"}
OpTypeKey["comment_payout_update"] = []string{"posting"}
OpTypeKey["return_vesting_delegation"] = []string{"posting"}
OpTypeKey["comment_benefactor_reward"] = []string{"posting"}
}
//SigningKeys returns the key from the CurrentKeys
func (client *Client) SigningKeys(trx types.Operation) ([][]byte, error) {
var keys [][]byte
if client.CurrentKeys == nil {
return nil, errors.New("client Keys not initialized. Use SetKeys method")
}
opKeys := OpTypeKey[trx.Type()]
for _, val := range opKeys {
switch {
case val == "posting":
for _, keyStr := range client.CurrentKeys.PKey {
privKey, err := wif.Decode(keyStr)
if err != nil {
return nil, errors.New("error decode Posting Key: " + err.Error())
}
keys = append(keys, privKey)
}
case val == "active":
for _, keyStr := range client.CurrentKeys.AKey {
privKey, err := wif.Decode(keyStr)
if err != nil {
return nil, errors.New("error decode Active Key: " + err.Error())
}
keys = append(keys, privKey)
}
case val == "owner":
for _, keyStr := range client.CurrentKeys.OKey {
privKey, err := wif.Decode(keyStr)
if err != nil {
return nil, errors.New("error decode Owner Key: " + err.Error())
}
keys = append(keys, privKey)
}
case val == "memo":
for _, keyStr := range client.CurrentKeys.MKey {
privKey, err := wif.Decode(keyStr)
if err != nil {
return nil, errors.New("error decode Memo Key: " + err.Error())
}
keys = append(keys, privKey)
}
}
}
return keys, nil
}