Skip to content

Commit

Permalink
fix pos GetTransactionByNumber return (#199)
Browse files Browse the repository at this point in the history
* fix pos GetTransactionByNumber return

* nil
  • Loading branch information
wangdayong228 authored Nov 17, 2022
1 parent dabd37a commit 8176650
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
8 changes: 8 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
providers "github.com/openweb3/go-rpc-provider/provider_wrapper"
"github.com/pkg/errors"
. "github.com/smartystreets/goconvey/convey"
"github.com/stretchr/testify/assert"
)

func _TestNewClient(t *testing.T) {
Expand Down Expand Up @@ -125,3 +126,10 @@ func TestEstimateGasAndCollateralAlwaysWithGaspriceNil(t *testing.T) {
To: defaultAccount,
})
}

func _TestGetPosTxByNum(t *testing.T) {
c := MustNewClient("https://test-internal.confluxrpc.com", ClientOption{Logger: os.Stdout})
tx, err := c.Pos().GetTransactionByNumber(*types.NewUint64(0x76657))
assert.NoError(t, err)
fmt.Printf("%v\n", tx)
}
40 changes: 11 additions & 29 deletions types/pos/pos.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,6 @@ func (b *Transaction) UnmarshalJSON(data []byte) error {
Type string `json:"type"`
}

type tmpPayload struct {
ElectionPayload
RetirePayload
// RegisterPayload
UpdateVotingPowerPayload
PivotBlockDecision
DisputePayload
ConflictSignature
}

tmpTx := tmpTransaction{}

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

if tmpTx.Payload != nil {
marshaed, err := json.Marshal(tmpTx.Payload)
if err != nil {
return errors.WithStack(err)
}

payload := tmpPayload{}
err = json.Unmarshal(marshaed, &payload)
marshaled, err := json.Marshal(tmpTx.Payload)
if err != nil {
return errors.WithStack(err)
}

realPayload := TransactionPayload{}
realPayload.SetTransactionType(tmpTx.Type)
switch tmpTx.Type {
case "Election":
realPayload.ElectionPayload = payload.ElectionPayload
err = json.Unmarshal(marshaled, &realPayload.ElectionPayload)
case "Retire":
realPayload.RetirePayload = payload.RetirePayload
err = json.Unmarshal(marshaled, &realPayload.RetirePayload)
case "Register":
realPayload.RegisterPayload = RegisterPayload{
PublicKey: payload.ElectionPayload.PublicKey,
VrfPublicKey: payload.ElectionPayload.VrfPublicKey,
}
// fmt.Printf("realPayload.RegisterPayload: %#v\n\n", realPayload.RegisterPayload)
err = json.Unmarshal(marshaled, &realPayload.RegisterPayload)
case "UpdateVotingPower":
realPayload.UpdateVotingPowerPayload = payload.UpdateVotingPowerPayload
err = json.Unmarshal(marshaled, &realPayload.UpdateVotingPowerPayload)
case "PivotDecision":
realPayload.PivotBlockDecision = payload.PivotBlockDecision
err = json.Unmarshal(marshaled, &realPayload.PivotBlockDecision)
case "Dispute":
realPayload.DisputePayload = payload.DisputePayload
err = json.Unmarshal(marshaled, &realPayload.DisputePayload)
}
if err != nil {
return errors.WithStack(err)
}

realPayload.SetTransactionType(tmpTx.Type)
// fmt.Printf("tmpTxType:%v,payload:%#v, realPayload %#v", tmpTx.Type, payload, realPayload)
b.Payload = &realPayload
}

Expand Down
14 changes: 10 additions & 4 deletions types/pos/transaction_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ type PivotBlockDecision struct {
}

type DisputePayload struct {
Address Address `json:"address"`
BlsPubKey string `json:"blsPubKey"`
VrfPubKey string `json:"vrfPubKey"`
ConflictingVotes ConflictSignature `json:"conflictingVotes"`
Address Address `json:"address"`
BlsPublicKey string `json:"blsPublicKey"`
VrfPublicKey string `json:"vrfPublicKey"`
ConflictingVotes ConflictingVotes `json:"conflictingVotes"`
}

type ConflictingVotes struct {
ConflictVoteType string `json:"conflictVoteType"`
First string `json:"first"`
Second string `json:"second"`
}

type ConflictSignature struct {
Expand Down

0 comments on commit 8176650

Please sign in to comment.