-
Notifications
You must be signed in to change notification settings - Fork 39
/
cmt.go
677 lines (565 loc) · 20.7 KB
/
cmt.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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
package api
import (
"bytes"
"encoding/base64"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math/big"
"github.com/spf13/cast"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
ttypes "github.com/tendermint/tendermint/types"
tmcmn "github.com/tendermint/tendermint/libs/common"
"github.com/CyberMiles/travis/modules/governance"
"github.com/CyberMiles/travis/modules/stake"
"github.com/CyberMiles/travis/sdk"
"github.com/CyberMiles/travis/types"
"github.com/CyberMiles/travis/utils"
)
// CmtRPCService offers cmt related RPC methods
type CmtRPCService struct {
backend *Backend
am *accounts.Manager
nonceLock *AddrLocker
}
func NewCmtRPCService(b *Backend, nonceLock *AddrLocker) *CmtRPCService {
return &CmtRPCService{
backend: b,
am: b.ethereum.AccountManager(),
nonceLock: nonceLock,
}
}
func (s *CmtRPCService) makeTravisTxArgs(tx sdk.Tx, address common.Address, nonce *hexutil.Uint64) (*SendTxArgs, error) {
data, err := tx.MarshalJSON()
if err != nil {
return nil, err
}
zeroUint := hexutil.Uint64(0)
zeroBigInt := big.NewInt(0)
return &SendTxArgs{
address,
nil,
&zeroUint,
(*hexutil.Big)(zeroBigInt),
(*hexutil.Big)(zeroBigInt),
nonce,
(*hexutil.Bytes)(&data),
nil,
}, nil
}
// sign tx and broadcast commit to tendermint.
func (s *CmtRPCService) signAndBroadcastTxCommit(args *SendTxArgs) (*ctypes.ResultBroadcastTxCommit, error) {
signTx := func(args *SendTxArgs) (*ethTypes.Transaction, error) {
if args.Nonce == nil {
// Hold the addresse's mutex around signing to prevent concurrent assignment of
// the same nonce to multiple accounts.
s.nonceLock.LockAddr(args.From)
// release noncelock after sign
defer s.nonceLock.UnlockAddr(args.From)
}
return s.backend.signTransaction(args)
}
signed, err := signTx(args)
if err != nil {
return nil, err
}
return s.backend.BroadcastTxCommit(signed)
}
// SendRawTx will broadcast the signed transaction to tendermint.
// The sender is responsible for signing the transaction and using the correct nonce.
func (s *CmtRPCService) SendRawTx(encodedTx hexutil.Bytes) (*ctypes.ResultBroadcastTxCommit, error) {
tx := new(ethTypes.Transaction)
if err := rlp.DecodeBytes(encodedTx, tx); err != nil {
return nil, err
}
if utils.IsEthTx(tx) {
result, err := s.backend.BroadcastTxSync(tx)
if err != nil {
return nil, err
}
if result.Code > 0 {
return nil, errors.New(result.Log)
}
return &ctypes.ResultBroadcastTxCommit{
Hash: ttypes.Tx(encodedTx).Hash(), //tx.Hash().Hex(),
}, nil
} else {
return s.backend.BroadcastTxCommit(tx)
}
}
// GetBlockByNumber returns the requested block by height.
func (s *CmtRPCService) GetBlockByNumber(height uint64, decodeTx bool) (*ctypes.ResultBlock, error) {
h := cast.ToInt64(height)
block, err := s.backend.GetLocalClient().Block(&h)
if err != nil {
return nil, err
}
if !decodeTx {
return block, err
}
// decode txs
formatTx := func(index int) ([]byte, error) {
// get transaction by hash
tx := ttypes.Tx(block.Block.Txs[index])
rpcTx, err := s.GetTransactionByHash(hex.EncodeToString(tx.Hash()))
b, err := json.Marshal(rpcTx)
return b, err
}
txs := block.Block.Txs
for i := range txs {
if txs[i], err = formatTx(i); err != nil {
return nil, err
}
}
return block, nil
}
// RPCTransaction represents a transaction that will serialize to the RPC representation of a transaction
type RPCTransaction struct {
BlockNumber *hexutil.Big `json:"blockNumber"`
From common.Address `json:"from"`
Gas hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"`
Hash common.Hash `json:"hash"`
CmtHash tmcmn.HexBytes `json:"cmtHash"`
Input hexutil.Bytes `json:"input"`
CmtInput interface{} `json:"cmtInput"`
Nonce hexutil.Uint64 `json:"nonce"`
To *common.Address `json:"to"`
TransactionIndex hexutil.Uint `json:"transactionIndex"`
Value *hexutil.Big `json:"value"`
V *hexutil.Big `json:"v"`
R *hexutil.Big `json:"r"`
S *hexutil.Big `json:"s"`
TxResult abci.ResponseDeliverTx `json:"txResult"`
}
// newRPCTransaction returns a transaction that will serialize to the RPC representation.
func newRPCTransaction(res *ctypes.ResultTx) (*RPCTransaction, error) {
tx := new(ethTypes.Transaction)
rlpStream := rlp.NewStream(bytes.NewBuffer(res.Tx), 0)
if err := tx.DecodeRLP(rlpStream); err != nil {
return nil, err
}
signer := ethTypes.NewEIP155Signer(tx.ChainId())
from, _ := ethTypes.Sender(signer, tx)
v, r, s := tx.RawSignatureValues()
var travisTx sdk.Tx
if !utils.IsEthTx(tx) {
if err := json.Unmarshal(tx.Data(), &travisTx); err != nil {
return nil, err
}
}
return &RPCTransaction{
BlockNumber: (*hexutil.Big)(big.NewInt(res.Height)),
From: from,
Gas: hexutil.Uint64(tx.Gas()),
GasPrice: (*hexutil.Big)(tx.GasPrice()),
Hash: tx.Hash(),
CmtHash: res.Hash,
Input: hexutil.Bytes(tx.Data()),
CmtInput: travisTx,
Nonce: hexutil.Uint64(tx.Nonce()),
To: tx.To(),
TransactionIndex: hexutil.Uint(res.Index),
Value: (*hexutil.Big)(tx.Value()),
V: (*hexutil.Big)(v),
R: (*hexutil.Big)(r),
S: (*hexutil.Big)(s),
TxResult: res.TxResult,
}, nil
}
// GetTransactionFromBlock returns the transaction for the given block number and index.
func (s *CmtRPCService) GetTransactionFromBlock(height uint64, index uint64) (*RPCTransaction, error) {
// get block
h := cast.ToInt64(height)
block, err := s.backend.GetLocalClient().Block(&h)
if err != nil {
return nil, err
}
// check index
if cast.ToInt64(index) >= block.Block.NumTxs {
return nil, errors.New(fmt.Sprintf("No transaction in block %d, index %d. ", height, index))
}
// get transaction by hash
tx := ttypes.Tx(block.Block.Txs[index])
return s.GetTransactionByHash(hex.EncodeToString(tx.Hash()))
}
// GetTransactionByHash returns the transaction for the given hash
func (s *CmtRPCService) GetTransactionByHash(hash string) (*RPCTransaction, error) {
// bytes from hash string
bkey, err := hex.DecodeString(cmn.StripHex(hash))
if err != nil {
return nil, err
}
// get transaction
res, err := s.backend.GetLocalClient().Tx(bkey, false)
if err != nil {
return nil, err
}
return newRPCTransaction(res)
}
// DecodeRawTxs returns the transactions from the raw tx array in the block data
func (s *CmtRPCService) DecodeRawTxs(rawTxs []string) ([]*RPCTransaction, error) {
txs := make([]*RPCTransaction, len(rawTxs))
for index, raw := range rawTxs {
tx, err := base64.StdEncoding.DecodeString(raw)
if err != nil {
return txs, err
}
rpcTx, err := newRPCTransaction(&ctypes.ResultTx{Tx: tx})
if err != nil {
return txs, err
}
txs[index] = rpcTx
}
return txs, nil
}
// Info about the node's syncing state
func (s *CmtRPCService) Syncing() (*ctypes.SyncInfo, error) {
status, err := s.backend.GetLocalClient().Status()
if err != nil {
return nil, err
}
return &status.SyncInfo, nil
}
type DeclareCandidacyArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
PubKey string `json:"pubKey"`
MaxAmount hexutil.Big `json:"maxAmount"`
CompRate sdk.Rat `json:"compRate"`
Description stake.Description `json:"description"`
}
func (s *CmtRPCService) DeclareCandidacy(args DeclareCandidacyArgs) (*ctypes.ResultBroadcastTxCommit, error) {
pubKey, err := types.GetPubKey(args.PubKey)
if err != nil {
return nil, err
}
tx := stake.NewTxDeclareCandidacy(pubKey, args.MaxAmount.ToInt().String(), args.CompRate, args.Description)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type WithdrawCandidacyArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
}
func (s *CmtRPCService) WithdrawCandidacy(args WithdrawCandidacyArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := stake.NewTxWithdrawCandidacy()
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type UpdateCandidacyArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
PubKey string `json:"pubKey"`
MaxAmount *hexutil.Big `json:"maxAmount"`
CompRate sdk.Rat `json:"compRate"`
Description stake.Description `json:"description"`
}
func (s *CmtRPCService) UpdateCandidacy(args UpdateCandidacyArgs) (*ctypes.ResultBroadcastTxCommit, error) {
maxAmount := ""
if args.MaxAmount != nil {
maxAmount = args.MaxAmount.ToInt().String()
}
pubKey := types.PubKey{}
if !utils.IsBlank(args.PubKey) {
tmp, err := types.GetPubKey(args.PubKey)
if err != nil {
return nil, err
}
pubKey = tmp
}
tx := stake.NewTxUpdateCandidacy(pubKey, maxAmount, args.CompRate, args.Description)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type ActivateCandidacyArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
}
func (s *CmtRPCService) ActivateCandidacy(args ActivateCandidacyArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := stake.NewTxActivateCandidacy()
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type DeactivateCandidacyArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
}
func (s *CmtRPCService) DeactivateCandidacy(args DeactivateCandidacyArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := stake.NewTxDeactivateCandidacy()
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type SetCompRateArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
DelegatorAddress common.Address `json:"delegatorAddress"`
CompRate sdk.Rat `json:"compRate"`
}
func (s *CmtRPCService) SetCompRate(args SetCompRateArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := stake.NewTxSetCompRate(args.DelegatorAddress, args.CompRate)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type UpdateCandidacyAccountArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
NewCandidateAddress common.Address `json:"newCandidateAccount"`
}
func (s *CmtRPCService) UpdateCandidacyAccount(args UpdateCandidacyAccountArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := stake.NewTxUpdateCandidacyAccount(args.NewCandidateAddress)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type AcceptCandidacyAccountUpdateArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
AccountUpdateRequestId int64 `json:"accountUpdateRequestId"`
}
func (s *CmtRPCService) AcceptCandidacyAccountUpdate(args AcceptCandidacyAccountUpdateArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := stake.NewTxAcceptCandidacyAccountUpdate(args.AccountUpdateRequestId)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type VerifyCandidacyArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
CandidateAddress common.Address `json:"candidateAddress"`
Verified bool `json:"verified"`
}
func (s *CmtRPCService) VerifyCandidacy(args VerifyCandidacyArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := stake.NewTxVerifyCandidacy(args.CandidateAddress, args.Verified)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type DelegateArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
ValidatorAddress common.Address `json:"validatorAddress"`
Amount hexutil.Big `json:"amount"`
CubeBatch string `json:"cubeBatch"`
Sig string `json:"sig"`
}
func (s *CmtRPCService) Delegate(args DelegateArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := stake.NewTxDelegate(args.ValidatorAddress, args.Amount.ToInt().String(), args.CubeBatch, args.Sig)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type WithdrawArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
ValidatorAddress common.Address `json:"validatorAddress"`
Amount hexutil.Big `json:"amount"`
}
func (s *CmtRPCService) Withdraw(args WithdrawArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := stake.NewTxWithdraw(args.ValidatorAddress, args.Amount.ToInt().String())
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type StakeQueryResult struct {
Height int64 `json:"height"`
Data interface{} `json:"data"`
}
func (s *CmtRPCService) QueryValidators(height uint64) (*StakeQueryResult, error) {
var candidates stake.Candidates
h, err := s.getParsedFromJson("/validators", []byte{0}, &candidates, height)
if err != nil {
return nil, err
}
return &StakeQueryResult{h, candidates}, nil
}
func (s *CmtRPCService) QueryValidator(address common.Address, height uint64) (*StakeQueryResult, error) {
var candidate stake.Candidate
h, err := s.getParsedFromJson("/validator", []byte(address.Hex()), &candidate, height)
if err != nil {
return nil, err
}
return &StakeQueryResult{h, &candidate}, nil
}
func (s *CmtRPCService) QueryDelegator(address common.Address, height uint64) (*StakeQueryResult, error) {
var slotDelegates []*stake.Delegation
h, err := s.getParsedFromJson("/delegator", []byte(address.Hex()), &slotDelegates, height)
if err != nil {
return nil, err
}
return &StakeQueryResult{h, slotDelegates}, nil
}
func (s *CmtRPCService) QueryAwardInfos(height uint64) (*StakeQueryResult, error) {
var awardInfos stake.AwardInfos
h, err := s.getParsedFromJson("/awardInfo", utils.AwardInfosKey, &awardInfos, height)
if err != nil {
return nil, err
}
return &StakeQueryResult{h, awardInfos}, nil
}
func (s *CmtRPCService) QueryAbsentValidatorsKey(height uint64) (*StakeQueryResult, error) {
var absentValidators stake.AbsentValidators
h, err := s.getParsedFromJson("/key", utils.AbsentValidatorsKey, &absentValidators, height)
if err != nil {
return nil, err
}
return &StakeQueryResult{h, absentValidators}, nil
}
type GovernanceTransferFundProposalArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
TransferFrom common.Address `json:"transferFrom"`
TransferTo common.Address `json:"transferTo"`
Amount hexutil.Big `json:"amount"`
Reason string `json:"reason"`
ExpireTimestamp *int64 `json:"expireTimestamp"`
ExpireBlockHeight *int64 `json:"expireBlockHeight"`
}
func (s *CmtRPCService) ProposeTransferFund(args GovernanceTransferFundProposalArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := governance.NewTxTransferFundPropose(&args.TransferFrom, &args.TransferTo,
args.Amount.ToInt().String(), args.Reason,
args.ExpireTimestamp, args.ExpireBlockHeight)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type GovernanceChangeParamProposalArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
Name string `json:"name"`
Value string `json:"value"`
Reason string `json:"reason"`
ExpireTimestamp *int64 `json:"expireTimestamp"`
ExpireBlockHeight *int64 `json:"expireBlockHeight"`
}
func (s *CmtRPCService) ProposeChangeParam(args GovernanceChangeParamProposalArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := governance.NewTxChangeParamPropose(args.Name, args.Value, args.Reason,
args.ExpireTimestamp, args.ExpireBlockHeight)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type GovernanceDeployLibEniProposalArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
Name string `json:"name"`
Version string `json:"version"`
FileUrl string `json:"fileUrl"`
Md5 string `json:"md5"`
Reason string `json:"reason"`
DeployTimestamp *int64 `json:"deployTimestamp"`
DeployBlockHeight *int64 `json:"deployBlockHeight"`
}
func (s *CmtRPCService) ProposeDeployLibEni(args GovernanceDeployLibEniProposalArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := governance.NewTxDeployLibEniPropose(args.Name, args.Version, args.FileUrl, args.Md5, args.Reason,
args.DeployTimestamp, args.DeployBlockHeight)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type GovernanceRetireProgramProposalArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
PreservedValidators string `json:"preservedValidators"`
Reason string `json:"reason"`
RetiredBlockHeight *int64 `json:"retiredBlockHeight"`
}
func (s *CmtRPCService) ProposeRetireProgram(args GovernanceRetireProgramProposalArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := governance.NewTxRetireProgramPropose(args.PreservedValidators, args.Reason, args.RetiredBlockHeight)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type GovernanceUpgradeProgramProposalArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
From common.Address `json:"from"`
Name string `json:"name"`
Version string `json:"version"`
FileUrl string `json:"fileUrl"`
Md5 string `json:"md5"`
Reason string `json:"reason"`
UpgradeBlockHeight *int64 `json:"upgradeBlockHeight"`
}
func (s *CmtRPCService) ProposeUpgradeProgram(args GovernanceUpgradeProgramProposalArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := governance.NewTxUpgradeProgramPropose(args.Name,
args.Version, args.FileUrl, args.Md5, args.Reason, args.UpgradeBlockHeight)
txArgs, err := s.makeTravisTxArgs(tx, args.From, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
type GovernanceVoteArgs struct {
Nonce *hexutil.Uint64 `json:"nonce"`
Voter common.Address `json:"from"`
ProposalId string `json:"proposalId"`
Answer string `json:"answer"`
}
func (s *CmtRPCService) Vote(args GovernanceVoteArgs) (*ctypes.ResultBroadcastTxCommit, error) {
tx := governance.NewTxVote(args.ProposalId, args.Answer)
txArgs, err := s.makeTravisTxArgs(tx, args.Voter, args.Nonce)
if err != nil {
return nil, err
}
return s.signAndBroadcastTxCommit(txArgs)
}
func (s *CmtRPCService) QueryProposals() (*StakeQueryResult, error) {
var proposals []*governance.Proposal
h, err := s.getParsedFromJson("/governance/proposals", []byte{0}, &proposals, 0)
if err != nil {
return nil, err
}
return &StakeQueryResult{h, proposals}, nil
}
func (s *CmtRPCService) QueryParams(height uint64) (*StakeQueryResult, error) {
var params utils.Params
h, err := s.getParsedFromJson("/key", utils.ParamKey, ¶ms, height)
if err != nil {
return nil, err
}
return &StakeQueryResult{h, params}, nil
}