-
Notifications
You must be signed in to change notification settings - Fork 2
/
util.go
60 lines (56 loc) · 1.4 KB
/
util.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
package call
import (
"context"
"github.com/empow-blockchain/go-empow/core/tx"
"github.com/empow-blockchain/go-empow/rpc/pb"
)
// ToTxRequest ...
func ToTxRequest(t *tx.Tx) *rpcpb.TransactionRequest {
ret := &rpcpb.TransactionRequest{
Time: t.Time,
Expiration: t.Expiration,
GasRatio: float64(t.GasRatio) / 100,
GasLimit: float64(t.GasLimit) / 100,
Delay: t.Delay,
Signers: t.Signers,
Publisher: t.Publisher,
ChainId: t.ChainID,
}
for _, a := range t.Actions {
ret.Actions = append(ret.Actions, &rpcpb.Action{
Contract: a.Contract,
ActionName: a.ActionName,
Data: a.Data,
})
}
for _, a := range t.AmountLimit {
ret.AmountLimit = append(ret.AmountLimit, &rpcpb.AmountLimit{
Token: a.Token,
Value: a.Val,
})
}
for _, s := range t.Signs {
ret.Signatures = append(ret.Signatures, &rpcpb.Signature{
Algorithm: rpcpb.Signature_Algorithm(s.Algorithm),
PublicKey: s.Pubkey,
Signature: s.Sig,
})
}
for _, s := range t.PublishSigns {
ret.PublisherSigs = append(ret.PublisherSigs, &rpcpb.Signature{
Algorithm: rpcpb.Signature_Algorithm(s.Algorithm),
PublicKey: s.Pubkey,
Signature: s.Sig,
})
}
return ret
}
// SendTx ...
func SendTx(stx *tx.Tx, i int) (string, error) {
client := GetClient(i)
resp, err := client.SendTransaction(context.Background(), ToTxRequest(stx))
if err != nil {
return "", err
}
return resp.Hash, nil
}