mirror of
https://github.com/scroll-tech/scroll.git
synced 2026-04-23 03:00:50 -04:00
big.Int
This commit is contained in:
@@ -55,7 +55,7 @@ func (c *ProverTaskController) GetTasksByProver(ctx *gin.Context) {
|
||||
// @Accept string
|
||||
// @Produce json
|
||||
// @Param pubkey path string true "prover public key"
|
||||
// @Success 200 {object} map[string]decimal.Decimal
|
||||
// @Success 200 {object} map[string]*big.Int
|
||||
// @Failure 404 {object} string
|
||||
// @Failure 500 {object} string
|
||||
// @Router /prover_task/total_rewards/{pubkey} [get]
|
||||
|
||||
@@ -2,7 +2,7 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/shopspring/decimal"
|
||||
"math/big"
|
||||
|
||||
"scroll-tech/miner-api/internal/orm"
|
||||
)
|
||||
@@ -19,14 +19,14 @@ func (p *ProverTaskService) GetTasksByProver(pubkey string) ([]*orm.ProverTask,
|
||||
return p.db.GetProverTasksByProver(context.Background(), pubkey)
|
||||
}
|
||||
|
||||
func (p *ProverTaskService) GetTotalRewards(pubkey string) (decimal.Decimal, error) {
|
||||
func (p *ProverTaskService) GetTotalRewards(pubkey string) (*big.Int, error) {
|
||||
tasks, err := p.db.GetProverTasksByProver(context.Background(), pubkey)
|
||||
if err != nil {
|
||||
return decimal.Decimal{}, err
|
||||
return nil, err
|
||||
}
|
||||
rewards := decimal.New(0, 0)
|
||||
rewards := new(big.Int)
|
||||
for _, task := range tasks {
|
||||
rewards.Add(task.Reward)
|
||||
rewards.Add(rewards, task.Reward.BigInt())
|
||||
}
|
||||
return rewards, nil
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"github.com/shopspring/decimal"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gorm.io/gorm"
|
||||
"math/big"
|
||||
"scroll-tech/common/database"
|
||||
"scroll-tech/common/docker"
|
||||
"scroll-tech/common/types"
|
||||
@@ -82,7 +83,7 @@ func testGetTasksByProver(t *testing.T) {
|
||||
func testGetTotalRewards(t *testing.T) {
|
||||
rewards, err := service.GetTotalRewards(proverPubkey)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, decimal.NewFromInt(22), rewards)
|
||||
assert.Equal(t, big.NewInt(22), rewards)
|
||||
}
|
||||
|
||||
func testGetTask(t *testing.T) {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gorm.io/gorm"
|
||||
"io"
|
||||
"math/big"
|
||||
"net/http"
|
||||
"scroll-tech/common/database"
|
||||
"scroll-tech/common/docker"
|
||||
@@ -60,9 +61,9 @@ func testGetProverTasksByProver(t *testing.T) {
|
||||
}
|
||||
|
||||
func testGetTotalRewards(t *testing.T) {
|
||||
rewards := make(map[string]int)
|
||||
rewards := make(map[string]*big.Int)
|
||||
getResp(t, fmt.Sprintf("%s/total_rewards?pubkey=%s", basicPath, proverPubkey), &rewards)
|
||||
assert.Equal(t, 22, rewards["rewards"])
|
||||
assert.Equal(t, big.NewInt(22), rewards["rewards"])
|
||||
}
|
||||
|
||||
func testGetProverTask(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user