github.com/mavryk-network/mvgo@v1.19.9/rpc/staking.go (about) 1 // Copyright (c) 2023 Blockwatch Data Inc. 2 // Author: alex@blockwatch.cc 3 4 package rpc 5 6 import ( 7 "context" 8 "fmt" 9 10 "github.com/mavryk-network/mvgo/mavryk" 11 ) 12 13 type StakingParameters struct { 14 Cycle int64 `json:"cycle"` 15 Limit int64 `json:"limit_of_staking_over_baking_millionth"` 16 Edge int64 `json:"edge_of_baking_over_staking_billionth"` 17 } 18 19 // GetDelegateStakingParams returns a delegate's current staking setup 20 func (c *Client) GetDelegateStakingParams(ctx context.Context, addr mavryk.Address, id BlockID) (*StakingParameters, error) { 21 u := fmt.Sprintf("chains/main/blocks/%s/context/delegates/%s/active_staking_parameters", id, addr) 22 p := &StakingParameters{} 23 if err := c.Get(ctx, u, p); err != nil { 24 return nil, err 25 } 26 return p, nil 27 } 28 29 // GetDelegatePendingStakingParams returns a delegate's future staking setup 30 func (c *Client) GetDelegatePendingStakingParams(ctx context.Context, addr mavryk.Address, id BlockID) ([]StakingParameters, error) { 31 u := fmt.Sprintf("chains/main/blocks/%s/context/delegates/%s/pending_staking_parameters", id, addr) 32 list := make([]StakingParameters, 0, 5) 33 if err := c.Get(ctx, u, &list); err != nil { 34 return nil, err 35 } 36 return list, nil 37 } 38 39 type FrozenDeposit struct { 40 Cycle int64 `json:"cycle"` 41 Deposit int64 `json:"deposit,string"` 42 } 43 44 // GetUnstakedFrozenDeposits returns a delegate's unstaked frozen deposits 45 func (c *Client) GetUnstakedFrozenDeposits(ctx context.Context, addr mavryk.Address, id BlockID) ([]FrozenDeposit, error) { 46 u := fmt.Sprintf("chains/main/blocks/%s/context/delegates/%s/unstaked_frozen_deposits", id, addr) 47 list := make([]FrozenDeposit, 0, 7) 48 if err := c.Get(ctx, u, &list); err != nil { 49 return nil, err 50 } 51 return list, nil 52 }