forked from fbsobreira/gotron-sdk
/
proposal.go
74 lines (62 loc) · 1.89 KB
/
proposal.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
package client
import (
"context"
"fmt"
"github.com/acgroupvn/gotron-sdk/pkg/common"
"github.com/acgroupvn/gotron-sdk/pkg/proto/api"
"github.com/acgroupvn/gotron-sdk/pkg/proto/core"
"github.com/golang/protobuf/proto"
)
// ProposalsList return all network proposals
func (g *GrpcClient) ProposalsList() (*api.ProposalList, error) {
ctx, cancel := context.WithTimeout(context.Background(), g.grpcTimeout)
defer cancel()
return g.Client.ListProposals(ctx, new(api.EmptyMessage))
}
// ProposalCreate create proposal based on parameter list
func (g *GrpcClient) ProposalCreate(from string, parameters map[int64]int64) (*api.TransactionExtention, error) {
var err error
contract := &core.ProposalCreateContract{
Parameters: parameters,
}
if contract.OwnerAddress, err = common.DecodeCheck(from); err != nil {
return nil, err
}
ctx, cancel := context.WithTimeout(context.Background(), g.grpcTimeout)
defer cancel()
tx, err := g.Client.ProposalCreate(ctx, contract)
if err != nil {
return nil, err
}
if proto.Size(tx) == 0 {
return nil, fmt.Errorf("bad transaction")
}
if tx.GetResult().GetCode() != 0 {
return nil, fmt.Errorf("%s", tx.GetResult().GetMessage())
}
return tx, nil
}
// ProposalApprove change URL info
func (g *GrpcClient) ProposalApprove(from string, id int64, confirm bool) (*api.TransactionExtention, error) {
var err error
contract := &core.ProposalApproveContract{
ProposalId: id,
IsAddApproval: confirm,
}
if contract.OwnerAddress, err = common.DecodeCheck(from); err != nil {
return nil, err
}
ctx, cancel := context.WithTimeout(context.Background(), g.grpcTimeout)
defer cancel()
tx, err := g.Client.ProposalApprove(ctx, contract)
if err != nil {
return nil, err
}
if proto.Size(tx) == 0 {
return nil, fmt.Errorf("bad transaction")
}
if tx.GetResult().GetCode() != 0 {
return nil, fmt.Errorf("%s", tx.GetResult().GetMessage())
}
return tx, nil
}