Skip to content

Commit 8176650

Browse files
fix pos GetTransactionByNumber return (#199)
* fix pos GetTransactionByNumber return * nil
1 parent dabd37a commit 8176650

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

client_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
providers "github.com/openweb3/go-rpc-provider/provider_wrapper"
2323
"github.com/pkg/errors"
2424
. "github.com/smartystreets/goconvey/convey"
25+
"github.com/stretchr/testify/assert"
2526
)
2627

2728
func _TestNewClient(t *testing.T) {
@@ -125,3 +126,10 @@ func TestEstimateGasAndCollateralAlwaysWithGaspriceNil(t *testing.T) {
125126
To: defaultAccount,
126127
})
127128
}
129+
130+
func _TestGetPosTxByNum(t *testing.T) {
131+
c := MustNewClient("https://test-internal.confluxrpc.com", ClientOption{Logger: os.Stdout})
132+
tx, err := c.Pos().GetTransactionByNumber(*types.NewUint64(0x76657))
133+
assert.NoError(t, err)
134+
fmt.Printf("%v\n", tx)
135+
}

types/pos/pos.go

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,6 @@ func (b *Transaction) UnmarshalJSON(data []byte) error {
134134
Type string `json:"type"`
135135
}
136136

137-
type tmpPayload struct {
138-
ElectionPayload
139-
RetirePayload
140-
// RegisterPayload
141-
UpdateVotingPowerPayload
142-
PivotBlockDecision
143-
DisputePayload
144-
ConflictSignature
145-
}
146-
147137
tmpTx := tmpTransaction{}
148138

149139
if err := json.Unmarshal(data, &tmpTx); err != nil {
@@ -154,39 +144,31 @@ func (b *Transaction) UnmarshalJSON(data []byte) error {
154144
tmpTx.Timestamp, tmpTx.Number, nil, tmpTx.Status, tmpTx.Type}
155145

156146
if tmpTx.Payload != nil {
157-
marshaed, err := json.Marshal(tmpTx.Payload)
158-
if err != nil {
159-
return errors.WithStack(err)
160-
}
161-
162-
payload := tmpPayload{}
163-
err = json.Unmarshal(marshaed, &payload)
147+
marshaled, err := json.Marshal(tmpTx.Payload)
164148
if err != nil {
165149
return errors.WithStack(err)
166150
}
167151

168152
realPayload := TransactionPayload{}
153+
realPayload.SetTransactionType(tmpTx.Type)
169154
switch tmpTx.Type {
170155
case "Election":
171-
realPayload.ElectionPayload = payload.ElectionPayload
156+
err = json.Unmarshal(marshaled, &realPayload.ElectionPayload)
172157
case "Retire":
173-
realPayload.RetirePayload = payload.RetirePayload
158+
err = json.Unmarshal(marshaled, &realPayload.RetirePayload)
174159
case "Register":
175-
realPayload.RegisterPayload = RegisterPayload{
176-
PublicKey: payload.ElectionPayload.PublicKey,
177-
VrfPublicKey: payload.ElectionPayload.VrfPublicKey,
178-
}
179-
// fmt.Printf("realPayload.RegisterPayload: %#v\n\n", realPayload.RegisterPayload)
160+
err = json.Unmarshal(marshaled, &realPayload.RegisterPayload)
180161
case "UpdateVotingPower":
181-
realPayload.UpdateVotingPowerPayload = payload.UpdateVotingPowerPayload
162+
err = json.Unmarshal(marshaled, &realPayload.UpdateVotingPowerPayload)
182163
case "PivotDecision":
183-
realPayload.PivotBlockDecision = payload.PivotBlockDecision
164+
err = json.Unmarshal(marshaled, &realPayload.PivotBlockDecision)
184165
case "Dispute":
185-
realPayload.DisputePayload = payload.DisputePayload
166+
err = json.Unmarshal(marshaled, &realPayload.DisputePayload)
167+
}
168+
if err != nil {
169+
return errors.WithStack(err)
186170
}
187171

188-
realPayload.SetTransactionType(tmpTx.Type)
189-
// fmt.Printf("tmpTxType:%v,payload:%#v, realPayload %#v", tmpTx.Type, payload, realPayload)
190172
b.Payload = &realPayload
191173
}
192174

types/pos/transaction_payload.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,16 @@ type PivotBlockDecision struct {
7373
}
7474

7575
type DisputePayload struct {
76-
Address Address `json:"address"`
77-
BlsPubKey string `json:"blsPubKey"`
78-
VrfPubKey string `json:"vrfPubKey"`
79-
ConflictingVotes ConflictSignature `json:"conflictingVotes"`
76+
Address Address `json:"address"`
77+
BlsPublicKey string `json:"blsPublicKey"`
78+
VrfPublicKey string `json:"vrfPublicKey"`
79+
ConflictingVotes ConflictingVotes `json:"conflictingVotes"`
80+
}
81+
82+
type ConflictingVotes struct {
83+
ConflictVoteType string `json:"conflictVoteType"`
84+
First string `json:"first"`
85+
Second string `json:"second"`
8086
}
8187

8288
type ConflictSignature struct {

0 commit comments

Comments
 (0)