This commit is contained in:
xinran chen
2023-07-12 12:08:35 +08:00
parent 9e8215c94f
commit 78ee952555
4 changed files with 11 additions and 9 deletions

View File

@@ -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]

View File

@@ -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
}

View File

@@ -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) {

View File

@@ -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) {