Skip to content

Commit

Permalink
added hrtype for quottery ActiveBets
Browse files Browse the repository at this point in the history
  • Loading branch information
0xluk committed Jul 15, 2024
1 parent 819c2c3 commit 383361f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
12 changes: 9 additions & 3 deletions clients/quottery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (c *Client) GetBetInfo(ctx context.Context, betID uint32) (hrtypes.BetInfo,
return bi, nil
}

func (c *Client) GetActiveBets(ctx context.Context) (nodetypes.ActiveBets, error) {
func (c *Client) GetActiveBets(ctx context.Context) (hrtypes.ActiveBets, error) {
rcf := connector.RequestContractFunction{
ContractIndex: nodetypes.QuotteryContractID,
InputType: nodetypes.ViewID.ActiveBet,
Expand All @@ -56,10 +56,16 @@ func (c *Client) GetActiveBets(ctx context.Context) (nodetypes.ActiveBets, error
var result nodetypes.ActiveBets
err := c.connector.PerformSmartContractRequest(ctx, rcf, nil, &result)
if err != nil {
return nodetypes.ActiveBets{}, errors.Wrap(err, "handling smart contract request")
return hrtypes.ActiveBets{}, errors.Wrap(err, "handling smart contract request")
}

return result, nil
var ab hrtypes.ActiveBets
err = ab.FromNodeType(result)
if err != nil {
return hrtypes.ActiveBets{}, errors.Wrap(err, "converting from node type")
}

return ab, nil
}

var QuotteryGetBetInfoRequest = connector.RequestContractFunction{
Expand Down
31 changes: 31 additions & 0 deletions clients/quottery/hrtypes/bets.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,34 @@ func quotteryGetMinute(data uint32) int {
func quotteryGetSecond(data uint32) int {
return int(data & 0b111111)
}

type ActiveBets struct {
Count uint32
BetIDs []uint32
}

func (ab *ActiveBets) FromNodeType(m nodetypes.ActiveBets) error {
abc := activeBetsConverter{rawActiveBets: m}

converted := abc.toType()
*ab = converted

return nil
}

type activeBetsConverter struct {
rawActiveBets nodetypes.ActiveBets
}

func (abc *activeBetsConverter) toType() ActiveBets {
betIDs := make([]uint32, 0, abc.rawActiveBets.Count)

for _, b := range abc.rawActiveBets.BetIDs {
betIDs = append(betIDs, b)
}

return ActiveBets{
Count: abc.rawActiveBets.Count,
BetIDs: betIDs,
}
}

0 comments on commit 383361f

Please sign in to comment.