Skip to content

Commit

Permalink
tmp, hit nil poiter bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaiba committed Feb 14, 2025
1 parent 01c91aa commit aae3c3c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
29 changes: 24 additions & 5 deletions node/exts/erc20reward/meta_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,9 @@ func init() {
{Name: "reward_root", Type: types.ByteaType, Nullable: true},
{Name: "end_block_hash", Type: types.ByteaType, Nullable: true},
{Name: "voters", Type: types.TextArrayType, Nullable: true},
{Name: "voter_signatures", Type: types.ByteaArrayType, Nullable: true},
{Name: "vote_amounts", Type: types.TextArrayType, Nullable: true},
{Name: "vote_nonces", Type: types.IntArrayType, Nullable: true},
{Name: "voter_signatures", Type: types.ByteaArrayType, Nullable: true},
},
},
AccessModifiers: []precompiles.Modifier{precompiles.PUBLIC, precompiles.VIEW},
Expand All @@ -955,8 +956,16 @@ func init() {
}
}

var voteAmts []string
if len(e.VoteAmounts) > 0 {
for _, item := range e.VoteAmounts {
voteAmts = append(voteAmts, item.String())
}
}

return resultFn([]any{e.ID, e.StartHeight, e.StartTime, *e.EndHeight, e.Root, e.BlockHash,
voters,
voteAmts,
e.VoteSigs,
e.VoteNonces,
})
Expand All @@ -983,8 +992,9 @@ func init() {
{Name: "reward_root", Type: types.ByteaType, Nullable: true},
{Name: "end_block_hash", Type: types.ByteaType, Nullable: true},
{Name: "voters", Type: types.TextArrayType, Nullable: true},
{Name: "voter_signatures", Type: types.ByteaArrayType, Nullable: true},
{Name: "vote_amounts", Type: types.TextArrayType, Nullable: true},
{Name: "vote_nonces", Type: types.IntArrayType, Nullable: true},
{Name: "voter_signatures", Type: types.ByteaArrayType, Nullable: true},
},
},
AccessModifiers: []precompiles.Modifier{precompiles.PUBLIC, precompiles.VIEW},
Expand All @@ -1002,8 +1012,16 @@ func init() {
}
}

var voteAmts []string
if len(e.VoteAmounts) > 0 {
for _, item := range e.VoteAmounts {
voteAmts = append(voteAmts, item.String())
}
}

return resultFn([]any{e.ID, e.StartHeight, e.StartTime, *e.EndHeight, e.Root, e.BlockHash,
voters,
voteAmts,
e.VoteSigs,
e.VoteNonces,
})
Expand Down Expand Up @@ -1458,9 +1476,10 @@ func (p *PendingEpoch) copy() *PendingEpoch {
}

type EpochVoteInfo struct {
Voters []ethcommon.Address
VoteSigs [][]byte
VoteNonces []int64
Voters []ethcommon.Address
VoteAmounts []*types.Decimal
VoteSigs [][]byte
VoteNonces []int64
}

// Epoch is a period in which rewards are distributed.
Expand Down
18 changes: 7 additions & 11 deletions node/exts/erc20reward/meta_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ func rowToEpoch(r *common.Row) (*Epoch, error) {
blockHash = r.Values[5].([]byte)
}

fmt.Printf("yaiba ===== %+v, %v, %T", r.Values[6], r.Values[6], r.Values[6])
var voters []ethcommon.Address
if r.Values[6] != nil {
rawVoters := r.Values[6].([][]byte)
Expand All @@ -426,13 +427,7 @@ func rowToEpoch(r *common.Row) (*Epoch, error) {

var amounts []*types.Decimal
if r.Values[7] != nil {
rawAmounts := r.Values[7].([][]*types.Decimal)
for _, rawAmount := range rawAmounts {
if rawAmount == nil {
continue
}
amounts = append(amounts, rawAmount...)
}
amounts = r.Values[7].([]*types.Decimal)
}

var voteNonces []int64
Expand All @@ -448,7 +443,7 @@ func rowToEpoch(r *common.Row) (*Epoch, error) {

var signatures [][]byte
if r.Values[9] != nil {
signatures = r.Values[7].([][]byte)
signatures = r.Values[9].([][]byte)
}

return &Epoch{
Expand All @@ -461,9 +456,10 @@ func rowToEpoch(r *common.Row) (*Epoch, error) {
BlockHash: blockHash,
Root: rewardRoot,
EpochVoteInfo: EpochVoteInfo{
Voters: voters,
VoteSigs: signatures,
VoteNonces: voteNonces,
Voters: voters,
VoteAmounts: amounts,
VoteSigs: signatures,
VoteNonces: voteNonces,
},
}, nil
}
Expand Down
6 changes: 4 additions & 2 deletions node/exts/erc20reward/named_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,9 @@ func init() {
{Name: "reward_root", Type: types.ByteaType, Nullable: true},
{Name: "end_block_hash", Type: types.ByteaType, Nullable: true},
{Name: "voters", Type: types.TextArrayType, Nullable: true},
{Name: "voter_signatures", Type: types.ByteaArrayType, Nullable: true},
{Name: "vote_amounts", Type: types.TextArrayType, Nullable: true},
{Name: "vote_nonces", Type: types.IntArrayType, Nullable: true},
{Name: "voter_signatures", Type: types.ByteaArrayType, Nullable: true},
},
},
AccessModifiers: []precompiles.Modifier{precompiles.PUBLIC, precompiles.VIEW},
Expand All @@ -245,8 +246,9 @@ func init() {
{Name: "reward_root", Type: types.ByteaType, Nullable: true},
{Name: "end_block_hash", Type: types.ByteaType, Nullable: true},
{Name: "voters", Type: types.TextArrayType, Nullable: true},
{Name: "voter_signatures", Type: types.ByteaArrayType, Nullable: true},
{Name: "vote_amounts", Type: types.TextArrayType, Nullable: true},
{Name: "vote_nonces", Type: types.IntArrayType, Nullable: true},
{Name: "voter_signatures", Type: types.ByteaArrayType, Nullable: true},
},
},
AccessModifiers: []precompiles.Modifier{precompiles.PUBLIC, precompiles.VIEW},
Expand Down

0 comments on commit aae3c3c

Please sign in to comment.