Skip to content
This repository was archived by the owner on Dec 15, 2024. It is now read-only.

Commit fda3b68

Browse files
committed
[types] LedgerInfoWithSigs, ValidatorSet, TxnPayloadScript update
1 parent 8d96497 commit fda3b68

12 files changed

+162
-78
lines changed

client/query_ledger.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,14 @@ func (c *Client) verifyLedgerInfoAndConsistency(
3939
) (*types.ProvenLedgerInfo, error) {
4040

4141
li := &types.LedgerInfoWithSignatures{}
42-
li.FromProto(resp.LedgerInfoWithSigs)
42+
if err := li.FromProto(resp.LedgerInfoWithSigs); err != nil {
43+
return nil, fmt.Errorf("unmarshal ledgerInfoWithSigs error: %v", err)
44+
}
45+
li0 := li.Value.(*types.LedgerInfoWithSignaturesV0)
4346

4447
verifier := c.verifier
4548
lastWaypoint := ""
46-
if verifier.EpochChangeVerificationRequired(li.Epoch) {
49+
if verifier.EpochChangeVerificationRequired(li0.Epoch) {
4750
vcp := &types.ValidatorChangeProof{}
4851
if err := vcp.FromProto(resp.ValidatorChangeProof); err != nil {
4952
return nil, fmt.Errorf("validator change proof invalid: %v", err)
@@ -70,7 +73,7 @@ func (c *Client) verifyLedgerInfoAndConsistency(
7073
lastWaypointB, _ := (&types.Waypoint{}).FromProvenLedgerInfo(pli).MarshalText()
7174
lastWaypoint = string(lastWaypointB)
7275
}
73-
pli, err := li.Verify(verifier)
76+
pli, err := li0.Verify(verifier)
7477
if err != nil {
7578
return nil, fmt.Errorf("ledger info verification failed: %v", err)
7679
}

client/state.go

+22-8
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ func (h HashValue) MarshalText() (text []byte, err error) {
3030

3131
// State represents the state of a client.
3232
type State struct {
33-
Waypoint string `toml:"waypoint" json:"waypoint"`
34-
ValidatorSet types.ValidatorSet `toml:"validator_set" json:"validator_set,omitempty"`
35-
Epoch uint64 `toml:"epoch" json:"epoch"`
36-
KnownVersion uint64 `toml:"known_version" json:"known_version"`
37-
Subtrees []HashValue `toml:"subtrees" json:"subtrees"`
33+
Waypoint string `toml:"waypoint" json:"waypoint"`
34+
VSScheme string `toml:"validator_set_scheme" json:"validator_set_scheme,omitempty"`
35+
ValidatorSet []*types.ValidatorInfo `toml:"validator_set" json:"validator_set,omitempty"`
36+
Epoch uint64 `toml:"epoch" json:"epoch"`
37+
KnownVersion uint64 `toml:"known_version" json:"known_version"`
38+
Subtrees []HashValue `toml:"subtrees" json:"subtrees"`
3839
}
3940

4041
// GetState returns the current state of a client.
@@ -45,7 +46,13 @@ func (c *Client) GetState() *State {
4546
cs := &State{}
4647
cs.Waypoint = c.lastWaypoint
4748
if vv, ok := c.verifier.(*types.ValidatorVerifier); ok {
48-
cs.ValidatorSet, cs.Epoch = vv.ToValidatorSet()
49+
var vs *types.ValidatorSet
50+
vs, cs.Epoch = vv.ToValidatorSet()
51+
cs.ValidatorSet = vs.Payload
52+
switch vs.Scheme.(type) {
53+
case types.SchemeED25519:
54+
cs.VSScheme = "ed25519"
55+
}
4956
}
5057
cs.KnownVersion = c.acc.NumLeaves - 1
5158
cs.Subtrees = cloneSubtrees2(c.acc.FrozenSubtreeRoots)
@@ -56,9 +63,16 @@ func (c *Client) GetState() *State {
5663
// SetState restores a client to a given state.
5764
func (c *Client) SetState(cs *State) error {
5865
var verifier types.LedgerInfoVerifier
59-
if len(cs.ValidatorSet) > 0 {
66+
if cs.ValidatorSet != nil {
6067
vv := &types.ValidatorVerifier{}
61-
if err := vv.FromValidatorSet(cs.ValidatorSet, cs.Epoch); err != nil {
68+
vs := &types.ValidatorSet{
69+
Payload: cs.ValidatorSet,
70+
}
71+
switch cs.VSScheme {
72+
case "ed25519":
73+
vs.Scheme = types.SchemeED25519{}
74+
}
75+
if err := vv.FromValidatorSet(vs, cs.Epoch); err != nil {
6276
return fmt.Errorf("restore validator set error: %v", err)
6377
}
6478
verifier = vv

client/transfer.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ func NewRawP2PTransaction(
2525
Sender: senderAddress,
2626
SequenceNumber: senderSequenceNumber,
2727
Payload: &types.TxnPayloadScript{
28-
Code: stdscript.PeerToPeerTransfer,
28+
Code: stdscript.PeerToPeerTransfer,
29+
TyArgs: []*types.TypeTag{types.LBRTypeTag()},
2930
Args: []types.TransactionArgument{
3031
types.TxnArgAddress(receiverAddress),
3132
types.TxnArgBytes(receiverAuthKeyPrefix),

go.mod

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/BurntSushi/toml v0.3.1
77
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
88
github.com/davecgh/go-spew v1.1.1 // indirect
9-
github.com/golang/protobuf v1.3.2
9+
github.com/golang/protobuf v1.3.5
1010
github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de
1111
github.com/johanbrandhorst/protobuf v0.7.1
1212
github.com/kr/pretty v0.1.0 // indirect
@@ -18,10 +18,10 @@ require (
1818
github.com/the729/lcs v0.1.4
1919
github.com/urfave/cli v1.22.1
2020
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392
21-
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 // indirect
22-
golang.org/x/sys v0.0.0-20190924135425-2f72d4f06240 // indirect
21+
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
22+
golang.org/x/sys v0.0.0-20200409092240-59c9f1ba88fa // indirect
2323
golang.org/x/text v0.3.2 // indirect
24-
google.golang.org/genproto v0.0.0-20190916214212-f660b8655731 // indirect
25-
google.golang.org/grpc v1.23.1
24+
google.golang.org/genproto v0.0.0-20200410110633-0848e9f44c36 // indirect
25+
google.golang.org/grpc v1.28.1
2626
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
2727
)

go.sum

+24
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
22
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
33
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4+
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
45
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
6+
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
57
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
68
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
79
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
810
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
911
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1012
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
13+
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
14+
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
15+
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
16+
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
1117
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
1218
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
1319
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
@@ -16,6 +22,10 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
1622
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
1723
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
1824
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
25+
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
26+
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
27+
github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls=
28+
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
1929
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
2030
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
2131
github.com/gopherjs/gopherjs v0.0.0-20191106031601-ce3c9ade29de h1:F7WD09S8QB4LrkEpka0dFPLSotH11HRpCsLIbIcJ7sU=
@@ -40,6 +50,7 @@ github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ=
4050
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
4151
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4252
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
53+
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
4354
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
4455
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
4556
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
@@ -71,6 +82,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2eP
7182
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
7283
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
7384
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
85+
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
86+
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
7487
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
7588
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
7689
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -81,6 +94,9 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
8194
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
8295
golang.org/x/sys v0.0.0-20190924135425-2f72d4f06240 h1:iLpJnvIAms/C7g3q9Gqq14Nuo4BOdygHa5TfyO3MzEE=
8396
golang.org/x/sys v0.0.0-20190924135425-2f72d4f06240/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
97+
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
98+
golang.org/x/sys v0.0.0-20200409092240-59c9f1ba88fa h1:mQTN3ECqfsViCNBgq+A40vdwhkGykrrQlYe3mPj6BoU=
99+
golang.org/x/sys v0.0.0-20200409092240-59c9f1ba88fa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
84100
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
85101
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
86102
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
@@ -95,11 +111,19 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl
95111
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
96112
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
97113
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
114+
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
98115
google.golang.org/genproto v0.0.0-20190916214212-f660b8655731 h1:Phvl0+G5t5k/EUFUi0wPdUUeTL2HydMQUXHnunWgSb0=
99116
google.golang.org/genproto v0.0.0-20190916214212-f660b8655731/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
117+
google.golang.org/genproto v0.0.0-20200410110633-0848e9f44c36 h1:QGM8iDIfHwTRMruKa7+aKDNRMQcWKeS6LDhdMiucYCE=
118+
google.golang.org/genproto v0.0.0-20200410110633-0848e9f44c36/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
100119
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
120+
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
101121
google.golang.org/grpc v1.23.1 h1:q4XQuHFC6I28BKZpo6IYyb3mNO+l7lSOxRuYTCiDfXk=
102122
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
123+
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
124+
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
125+
google.golang.org/grpc v1.28.1 h1:C1QC6KzgSiLyBabDi87BbjaGreoRgGUF5nOyvfrAZ1k=
126+
google.golang.org/grpc v1.28.1/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
103127
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
104128
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
105129
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

types/ledger_info.go

+30-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package types
22

33
import (
4-
"encoding/hex"
54
"errors"
65
"fmt"
76

@@ -19,17 +18,38 @@ type LedgerInfo struct {
1918
TransactionAccumulatorHash []byte
2019
Version uint64
2120
TimestampUsec uint64
22-
NextValidatorSet ValidatorSet `lcs:"optional"`
21+
NextValidatorSet *ValidatorSet `lcs:"optional"`
2322
ConsensusDataHash []byte
2423
}
2524

26-
// LedgerInfoWithSignatures is a ledger info with signature from trusted
27-
// validators.
2825
type LedgerInfoWithSignatures struct {
26+
Value isLedgerInfoWithSignatures `lcs:"enum=isLedgerInfoWithSignatures"`
27+
}
28+
29+
type isLedgerInfoWithSignatures interface {
30+
isLedgerInfoWithSignatures()
31+
}
32+
33+
// LedgerInfoWithSignaturesV0 is a ledger info with signature from trusted
34+
// validators.
35+
type LedgerInfoWithSignaturesV0 struct {
2936
*LedgerInfo
30-
Sigs map[string]HashValue
37+
Sigs map[AccountAddress]HashValue
38+
}
39+
40+
func (*LedgerInfoWithSignaturesV0) isLedgerInfoWithSignatures() {}
41+
42+
var ledgerInfoWSigsEnumDef = []lcs.EnumVariant{
43+
{
44+
Name: "isLedgerInfoWithSignatures",
45+
Value: 0,
46+
Template: (*LedgerInfoWithSignaturesV0)(nil),
47+
},
3148
}
3249

50+
// EnumTypes defines enum variants for lcs
51+
func (*LedgerInfoWithSignatures) EnumTypes() []lcs.EnumVariant { return ledgerInfoWSigsEnumDef }
52+
3353
// ProvenLedgerInfo is a ledger info proven to be history state of the ledger.
3454
type ProvenLedgerInfo struct {
3555
proven bool
@@ -73,30 +93,20 @@ func (l *LedgerInfo) Clone() *LedgerInfo {
7393
TransactionAccumulatorHash: cloneBytes(l.TransactionAccumulatorHash),
7494
Version: l.Version,
7595
TimestampUsec: l.TimestampUsec,
96+
NextValidatorSet: l.NextValidatorSet.Clone(),
7697
ConsensusDataHash: cloneBytes(l.ConsensusDataHash),
7798
}
78-
for _, v := range l.NextValidatorSet {
79-
out.NextValidatorSet = append(out.NextValidatorSet, v.Clone())
80-
}
8199
return out
82100
}
83101

84102
// FromProto parses a protobuf struct into this struct.
85103
func (l *LedgerInfoWithSignatures) FromProto(pb *pbtypes.LedgerInfoWithSignatures) error {
86-
l.LedgerInfo = &LedgerInfo{}
87-
l.LedgerInfo.FromProto(pb.LedgerInfo)
88-
89-
sigs := make(map[string]HashValue)
90-
for _, s := range pb.Signatures {
91-
sigs[hex.EncodeToString(s.ValidatorId)] = s.Signature
92-
}
93-
l.Sigs = sigs
94-
return nil
104+
return lcs.Unmarshal(pb.Bytes, l)
95105
}
96106

97107
// Verify the ledger info with a consensus verifier and output a ProvenLedgerInfo.
98-
func (l *LedgerInfoWithSignatures) Verify(v LedgerInfoVerifier) (*ProvenLedgerInfo, error) {
99-
if err := v.Verify(l); err != nil {
108+
func (l *LedgerInfoWithSignaturesV0) Verify(v LedgerInfoVerifier) (*ProvenLedgerInfo, error) {
109+
if err := v.Verify(&LedgerInfoWithSignatures{l}); err != nil {
100110
return nil, err
101111
}
102112
return &ProvenLedgerInfo{
@@ -143,7 +153,7 @@ func (pl *ProvenLedgerInfo) ToVerifier() (LedgerInfoVerifier, error) {
143153
if !pl.proven {
144154
panic("not valid proven ledger info")
145155
}
146-
if len(pl.ledgerInfo.NextValidatorSet) == 0 {
156+
if pl.ledgerInfo.NextValidatorSet == nil {
147157
return nil, errors.New("empty validator set")
148158
}
149159
vv := &ValidatorVerifier{}

types/raw_transaction.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ func (v *WriteOpWithPath) Clone() *WriteOpWithPath {
148148

149149
// TransactionPayload is the enum type of transaction payload
150150
type TransactionPayload interface {
151-
isTransactionPayload()
152151
Clone() TransactionPayload
153152
}
154153

@@ -173,8 +172,9 @@ func (v *TxnPayloadWriteSet) Clone() TransactionPayload {
173172

174173
// TxnPayloadScript is variant of TransactionPayload
175174
type TxnPayloadScript struct {
176-
Code []byte
177-
Args []TransactionArgument `lcs:"enum=TransactionArgument"`
175+
Code []byte
176+
TyArgs []*TypeTag
177+
Args []TransactionArgument `lcs:"enum=TransactionArgument"`
178178
}
179179

180180
// EnumTypes defines enum variants for lcs
@@ -196,10 +196,6 @@ type TxnPayloadModule []byte
196196
// Clone the transaction payload
197197
func (v TxnPayloadModule) Clone() TransactionPayload { return TxnPayloadModule(cloneBytes(v)) }
198198

199-
func (*TxnPayloadWriteSet) isTransactionPayload() {}
200-
func (*TxnPayloadScript) isTransactionPayload() {}
201-
func (TxnPayloadModule) isTransactionPayload() {}
202-
203199
// EnumTypes defines enum variants for lcs
204200
func (*RawTransaction) EnumTypes() []lcs.EnumVariant {
205201
return []lcs.EnumVariant{

types/txn_authenticator.go

-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package types
33
import "github.com/the729/lcs"
44

55
type TxnAuthenticator interface {
6-
isTxnAuthenticator()
76
Clone() TxnAuthenticator
87
}
98

@@ -19,8 +18,6 @@ type ED25519Authenticator struct {
1918

2019
// }
2120

22-
func (*ED25519Authenticator) isTxnAuthenticator() {}
23-
2421
// Clone the TxnAuthenticator
2522
func (v *ED25519Authenticator) Clone() TxnAuthenticator {
2623
out := &ED25519Authenticator{}

types/validator_change.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,26 @@ func (vcp *ValidatorChangeProof) Verify(v LedgerInfoVerifier) (*ProvenValidatorC
4343
}
4444
var genesisHash []byte
4545
for _, li := range vcp.LedgerInfoWithSigs {
46+
li0 := li.Value.(*LedgerInfoWithSignaturesV0)
4647
if err := v.Verify(li); err != nil {
4748
return nil, fmt.Errorf("some ledger info failed to verify: %v", err)
4849
}
49-
if li.Version == 0 {
50-
genesisHash = li.TransactionAccumulatorHash
50+
if li0.Version == 0 {
51+
genesisHash = li0.TransactionAccumulatorHash
5152
}
52-
if li.NextValidatorSet == nil {
53+
if li0.NextValidatorSet == nil {
5354
return nil, errors.New("ledger info doesn't carry validator set")
5455
}
5556
vv := &ValidatorVerifier{}
56-
if err := vv.FromValidatorSet(li.NextValidatorSet, li.Epoch+1); err != nil {
57+
if err := vv.FromValidatorSet(li0.NextValidatorSet, li0.Epoch+1); err != nil {
5758
return nil, fmt.Errorf("init new validator error: %v", err)
5859
}
5960
v = vv
6061
}
62+
lastLedger0 := vcp.LedgerInfoWithSigs[len(vcp.LedgerInfoWithSigs)-1].Value.(*LedgerInfoWithSignaturesV0)
6163
return &ProvenValidatorChange{
6264
proven: true,
63-
lastLedgerInfo: vcp.LedgerInfoWithSigs[len(vcp.LedgerInfoWithSigs)-1].LedgerInfo.Clone(),
65+
lastLedgerInfo: lastLedger0.LedgerInfo.Clone(),
6466
genesisHash: cloneBytes(genesisHash),
6567
}, nil
6668
}

0 commit comments

Comments
 (0)