Skip to content

Add coin response type given sui rpc update #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package types

import (
"errors"
"github.com/coming-chat/go-sui/v2/sui_types"
"math/big"
"sort"

"github.com/coming-chat/go-sui/v2/sui_types"
)

const SUI_COIN_TYPE = "0x2::sui::SUI"
Expand Down Expand Up @@ -36,7 +37,7 @@ func (c *Coin) Reference() *sui_types.ObjectRef {
}
}

type CoinPage = Page[Coin, sui_types.ObjectID]
type CoinPage = Page[Coin, string]

func (c *Coin) IsSUI() bool {
return c.CoinType == SUI_COIN_TYPE
Expand Down
13 changes: 6 additions & 7 deletions types/coin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

type suiAddress = sui_types.SuiAddress
type suiObjectID = sui_types.ObjectID

func balanceObject(val uint64) SafeSuiBigInt[uint64] {
return NewSafeSuiBigInt(val)
Expand Down Expand Up @@ -263,7 +262,7 @@ func TestPickupCoins(t *testing.T) {
{
name: "moreCount = 3",
args: args{
inputCoins: &Page[Coin, suiObjectID]{
inputCoins: &Page[Coin, string]{
Data: []Coin{
coin(1e3), coin(1e5), coin(1e2), coin(1e4),
},
Expand All @@ -282,7 +281,7 @@ func TestPickupCoins(t *testing.T) {
{
name: "large gas",
args: args{
inputCoins: &Page[Coin, suiObjectID]{
inputCoins: &Page[Coin, string]{
Data: []Coin{
coin(1e3), coin(1e5), coin(1e2), coin(1e4),
},
Expand All @@ -302,7 +301,7 @@ func TestPickupCoins(t *testing.T) {
{
name: "ErrNoCoinsFound",
args: args{
inputCoins: &Page[Coin, suiObjectID]{
inputCoins: &Page[Coin, string]{
Data: []Coin{},
},
targetAmount: *big.NewInt(101000),
Expand All @@ -312,7 +311,7 @@ func TestPickupCoins(t *testing.T) {
{
name: "ErrInsufficientBalance",
args: args{
inputCoins: &Page[Coin, suiObjectID]{
inputCoins: &Page[Coin, string]{
Data: []Coin{
coin(1e5), coin(1e6), coin(1e4),
},
Expand All @@ -324,7 +323,7 @@ func TestPickupCoins(t *testing.T) {
{
name: "ErrNeedMergeCoin 1",
args: args{
inputCoins: &Page[Coin, suiObjectID]{
inputCoins: &Page[Coin, string]{
Data: []Coin{
coin(1e5), coin(1e6), coin(1e4),
},
Expand All @@ -337,7 +336,7 @@ func TestPickupCoins(t *testing.T) {
{
name: "ErrNeedMergeCoin 2",
args: args{
inputCoins: &Page[Coin, suiObjectID]{
inputCoins: &Page[Coin, string]{
Data: []Coin{
coin(1e5), coin(1e6), coin(1e4), coin(1e5),
},
Expand Down
5 changes: 3 additions & 2 deletions types/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package types

import (
"fmt"
"math/big"

"github.com/coming-chat/go-sui/v2/sui_types"
"github.com/shopspring/decimal"
"math/big"
)

type SuiBigInt = decimal.Decimal
Expand Down Expand Up @@ -83,7 +84,7 @@ type ObjectOwner struct {
}

type Page[T SuiTransactionBlockResponse | SuiEvent | Coin | SuiObjectResponse | DynamicFieldInfo | string,
C sui_types.TransactionDigest | EventId | sui_types.ObjectID] struct {
C sui_types.TransactionDigest | EventId | sui_types.ObjectID | string] struct {
Data []T `json:"data"`
NextCursor *C `json:"nextCursor,omitempty"`
HasNextPage bool `json:"hasNextPage"`
Expand Down