Skip to content

Commit

Permalink
build(mod): upgrade to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Gkirito committed May 16, 2023
1 parent 8bdb0c5 commit 6d19e12
Show file tree
Hide file tree
Showing 37 changed files with 221 additions and 162 deletions.
4 changes: 2 additions & 2 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/hex"

"github.com/coming-chat/go-aptos/crypto/derivation"
"github.com/coming-chat/go-sui/lib"
"github.com/coming-chat/go-sui/sui_types"
"github.com/coming-chat/go-sui/v2/lib"
"github.com/coming-chat/go-sui/v2/sui_types"
"github.com/tyler-smith/go-bip39"
"golang.org/x/crypto/blake2b"
)
Expand Down
2 changes: 1 addition & 1 deletion account/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"testing"

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

Expand Down
6 changes: 3 additions & 3 deletions client/0_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import (
"strconv"
"testing"

"github.com/coming-chat/go-sui/sui_types"
"github.com/coming-chat/go-sui/types"
"github.com/coming-chat/go-sui/v2/sui_types"
"github.com/coming-chat/go-sui/v2/types"
"github.com/shopspring/decimal"

"github.com/coming-chat/go-sui/account"
"github.com/coming-chat/go-sui/v2/account"
"github.com/stretchr/testify/require"
)

Expand Down
65 changes: 38 additions & 27 deletions client/bcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"context"
"testing"

"github.com/coming-chat/go-sui/lib"
"github.com/coming-chat/go-sui/sui_types"
"github.com/coming-chat/go-sui/sui_types/sui_system_state"
"github.com/coming-chat/go-sui/types"
"github.com/coming-chat/go-sui/v2/lib"
"github.com/coming-chat/go-sui/v2/sui_types"
"github.com/coming-chat/go-sui/v2/sui_types/sui_system_state"
"github.com/coming-chat/go-sui/v2/types"
"github.com/fardream/go-bcs/bcs"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -40,10 +40,12 @@ func TestBCS_TransferObject(t *testing.T) {
require.NoError(t, err)

// build with remote rpc
txn, err := cli.TransferObject(context.Background(), *sender, *recipient,
txn, err := cli.TransferObject(
context.Background(), *sender, *recipient,
coin.CoinObjectId,
&gas.CoinObjectId,
types.NewSafeSuiBigInt(gasBudget))
types.NewSafeSuiBigInt(gasBudget),
)
require.NoError(t, err)
txBytesRemote := txn.TxBytes.Data()

Expand Down Expand Up @@ -78,9 +80,11 @@ func TestBCS_TransferSui(t *testing.T) {
require.NoError(t, err)

// build with remote rpc
txn, err := cli.TransferSui(context.Background(), *sender, *recipient, coin.CoinObjectId,
txn, err := cli.TransferSui(
context.Background(), *sender, *recipient, coin.CoinObjectId,
types.NewSafeSuiBigInt(amount),
types.NewSafeSuiBigInt(gasBudget))
types.NewSafeSuiBigInt(gasBudget),
)
require.NoError(t, err)
txBytesRemote := txn.TxBytes.Data()

Expand Down Expand Up @@ -160,11 +164,13 @@ func TestBCS_PayAllSui(t *testing.T) {
require.NoError(t, err)

// build with remote rpc
txn, err := cli.PayAllSui(context.Background(), *sender, *recipient,
txn, err := cli.PayAllSui(
context.Background(), *sender, *recipient,
[]suiObjectID{
coin.CoinObjectId, coin2.CoinObjectId,
},
types.NewSafeSuiBigInt(gasBudget))
types.NewSafeSuiBigInt(gasBudget),
)
require.NoError(t, err)
txBytesRemote := txn.TxBytes.Data()

Expand All @@ -191,7 +197,8 @@ func TestBCS_Pay(t *testing.T) {
err = ptb.Pay(
[]*sui_types.ObjectRef{coin.Reference()},
[]suiAddress{*recipient2, *recipient2},
[]uint64{amount, amount})
[]uint64{amount, amount},
)
require.NoError(t, err)
pt := ptb.Finish()
tx := sui_types.NewProgrammable(
Expand Down Expand Up @@ -240,29 +247,33 @@ func TestBCS_MoveCall(t *testing.T) {
// case 1: split target amount
amtArg, err := ptb.Pure(SUI(1).Uint64())
require.NoError(t, err)
arg1 := ptb.Command(sui_types.Command{
SplitCoins: &struct {
Argument sui_types.Argument
Arguments []sui_types.Argument
}{
Argument: sui_types.Argument{GasCoin: &lib.EmptyEnum{}},
Arguments: []sui_types.Argument{amtArg},
arg1 := ptb.Command(
sui_types.Command{
SplitCoins: &struct {
Argument sui_types.Argument
Arguments []sui_types.Argument
}{
Argument: sui_types.Argument{GasCoin: &lib.EmptyEnum{}},
Arguments: []sui_types.Argument{amtArg},
},
},
}) // the coin is split result argument
) // the coin is split result argument
arg2, err := ptb.Pure(validatorAddress)
require.NoError(t, err)
arg0, err := ptb.Obj(sui_types.SuiSystemMutObj)
require.NoError(t, err)
ptb.Command(sui_types.Command{
MoveCall: &sui_types.ProgrammableMoveCall{
Package: *sui_types.SuiSystemAddress,
Module: sui_system_state.SuiSystemModuleName,
Function: sui_types.AddStakeFunName,
Arguments: []sui_types.Argument{
arg0, arg1, arg2,
ptb.Command(
sui_types.Command{
MoveCall: &sui_types.ProgrammableMoveCall{
Package: *sui_types.SuiSystemAddress,
Module: sui_system_state.SuiSystemModuleName,
Function: sui_types.AddStakeFunName,
Arguments: []sui_types.Argument{
arg0, arg1, arg2,
},
},
},
})
)
pt := ptb.Finish()
tx := sui_types.NewProgrammable(
*sender, []*sui_types.ObjectRef{
Expand Down
6 changes: 3 additions & 3 deletions client/client_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"strings"

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

// NOTE: This copys the query limit from our Rust JSON RPC backend, this needs to be kept in sync!
Expand Down
6 changes: 3 additions & 3 deletions client/client_call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"math/big"
"testing"

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

"github.com/coming-chat/go-sui/types"
"github.com/coming-chat/go-sui/v2/types"
"github.com/stretchr/testify/require"
)

Expand Down
9 changes: 5 additions & 4 deletions client/client_call_unsafe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"math/big"
"testing"

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

"github.com/coming-chat/go-sui/account"
"github.com/coming-chat/go-sui/types"
"github.com/coming-chat/go-sui/v2/account"
"github.com/coming-chat/go-sui/v2/types"
"github.com/stretchr/testify/require"
)

Expand All @@ -22,7 +22,8 @@ func TestClient_TransferObject(t *testing.T) {
require.GreaterOrEqual(t, len(coins.Data), 2)
coin := coins.Data[0]

txn, err := cli.TransferObject(context.Background(), *signer, *recipient,
txn, err := cli.TransferObject(
context.Background(), *signer, *recipient,
coin.CoinObjectId, nil, types.NewSafeSuiBigInt(SUI(0.01).Uint64()),
)
require.Nil(t, err)
Expand Down
4 changes: 2 additions & 2 deletions client/client_nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package client
import (
"context"

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

// MintNFT
Expand Down
70 changes: 47 additions & 23 deletions client/client_stake.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package client
import (
"context"

"github.com/coming-chat/go-sui/lib"
"github.com/coming-chat/go-sui/sui_types"
"github.com/coming-chat/go-sui/sui_types/sui_system_state"
"github.com/coming-chat/go-sui/types"
"github.com/coming-chat/go-sui/v2/lib"
"github.com/coming-chat/go-sui/v2/sui_types"
"github.com/coming-chat/go-sui/v2/sui_types/sui_system_state"
"github.com/coming-chat/go-sui/v2/types"
"github.com/fardream/go-bcs/bcs"
)

Expand All @@ -30,17 +30,37 @@ func (c *Client) GetStakesByIds(ctx context.Context, stakedSuiIds []suiObjectID)
return resp, c.CallContext(ctx, &resp, getStakesByIds, stakedSuiIds)
}

func (c *Client) RequestAddStake(ctx context.Context, signer suiAddress, coins []suiObjectID, amount types.SuiBigInt, validator suiAddress, gas *suiObjectID, gasBudget types.SuiBigInt) (*types.TransactionBytes, error) {
func (c *Client) RequestAddStake(
ctx context.Context,
signer suiAddress,
coins []suiObjectID,
amount types.SuiBigInt,
validator suiAddress,
gas *suiObjectID,
gasBudget types.SuiBigInt,
) (*types.TransactionBytes, error) {
var resp types.TransactionBytes
return &resp, c.CallContext(ctx, &resp, requestAddStake, signer, coins, amount, validator, gas, gasBudget)
}

func (c *Client) RequestWithdrawStake(ctx context.Context, signer suiAddress, stakedSuiId suiObjectID, gas *suiObjectID, gasBudget types.SuiBigInt) (*types.TransactionBytes, error) {
func (c *Client) RequestWithdrawStake(
ctx context.Context,
signer suiAddress,
stakedSuiId suiObjectID,
gas *suiObjectID,
gasBudget types.SuiBigInt,
) (*types.TransactionBytes, error) {
var resp types.TransactionBytes
return &resp, c.CallContext(ctx, &resp, requestWithdrawStake, signer, stakedSuiId, gas, gasBudget)
}

func BCS_RequestAddStake(signer suiAddress, coins []*sui_types.ObjectRef, amount types.SafeSuiBigInt[uint64], validator suiAddress, gasPrice, gasBudget uint64) ([]byte, error) {
func BCS_RequestAddStake(
signer suiAddress,
coins []*sui_types.ObjectRef,
amount types.SafeSuiBigInt[uint64],
validator suiAddress,
gasPrice, gasBudget uint64,
) ([]byte, error) {
// build with BCS
ptb := sui_types.NewProgrammableTransactionBuilder()
amtArg, err := ptb.Pure(amount.Uint64())
Expand All @@ -51,30 +71,34 @@ func BCS_RequestAddStake(signer suiAddress, coins []*sui_types.ObjectRef, amount
if err != nil {
return nil, err
}
arg1 := ptb.Command(sui_types.Command{
SplitCoins: &struct {
Argument sui_types.Argument
Arguments []sui_types.Argument
}{
Argument: sui_types.Argument{GasCoin: &lib.EmptyEnum{}},
Arguments: []sui_types.Argument{amtArg},
arg1 := ptb.Command(
sui_types.Command{
SplitCoins: &struct {
Argument sui_types.Argument
Arguments []sui_types.Argument
}{
Argument: sui_types.Argument{GasCoin: &lib.EmptyEnum{}},
Arguments: []sui_types.Argument{amtArg},
},
},
}) // the coin is split result argument
) // the coin is split result argument
arg2, err := ptb.Pure(validator)
if err != nil {
return nil, err
}

ptb.Command(sui_types.Command{
MoveCall: &sui_types.ProgrammableMoveCall{
Package: *sui_types.SuiSystemAddress,
Module: sui_system_state.SuiSystemModuleName,
Function: sui_types.AddStakeFunName,
Arguments: []sui_types.Argument{
arg0, arg1, arg2,
ptb.Command(
sui_types.Command{
MoveCall: &sui_types.ProgrammableMoveCall{
Package: *sui_types.SuiSystemAddress,
Module: sui_system_state.SuiSystemModuleName,
Function: sui_types.AddStakeFunName,
Arguments: []sui_types.Argument{
arg0, arg1, arg2,
},
},
},
})
)
pt := ptb.Finish()
tx := sui_types.NewProgrammable(
signer, coins, pt, gasBudget, gasPrice,
Expand Down
7 changes: 4 additions & 3 deletions client/client_stake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"math/big"
"testing"

"github.com/coming-chat/go-sui/sui_types"
"github.com/coming-chat/go-sui/types"
"github.com/coming-chat/go-sui/v2/sui_types"
"github.com/coming-chat/go-sui/v2/types"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -88,7 +88,8 @@ func TestRequestAddDelegation(t *testing.T) {
validator, err := sui_types.NewAddressFromHex(validatorAddress)
require.Nil(t, err)

txBytes, err := BCS_RequestAddStake(*signer,
txBytes, err := BCS_RequestAddStake(
*signer,
pickedCoins.CoinRefs(),
types.NewSafeSuiBigInt(amount),
*validator,
Expand Down
2 changes: 1 addition & 1 deletion client/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"net/http"
"strings"

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

const (
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/coming-chat/go-sui
module github.com/coming-chat/go-sui/v2

go 1.18

Expand Down
2 changes: 1 addition & 1 deletion move_types/language_storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package move_types

import "github.com/coming-chat/go-sui/lib"
import "github.com/coming-chat/go-sui/v2/lib"

type StructTag struct {
Address AccountAddress
Expand Down
4 changes: 2 additions & 2 deletions sui_types/base_types.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package sui_types

import (
"github.com/coming-chat/go-sui/lib"
"github.com/coming-chat/go-sui/move_types"
"github.com/coming-chat/go-sui/v2/lib"
"github.com/coming-chat/go-sui/v2/move_types"
)

type SuiAddress = move_types.AccountAddress
Expand Down
4 changes: 2 additions & 2 deletions sui_types/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"crypto/ed25519"
"encoding/json"
"errors"
"github.com/coming-chat/go-sui/lib"
"github.com/coming-chat/go-sui/v2/lib"

"github.com/coming-chat/go-sui/crypto"
"github.com/coming-chat/go-sui/v2/crypto"
"github.com/fardream/go-bcs/bcs"
"golang.org/x/crypto/blake2b"
)
Expand Down
2 changes: 1 addition & 1 deletion sui_types/digest.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package sui_types

import "github.com/coming-chat/go-sui/lib"
import "github.com/coming-chat/go-sui/v2/lib"

type Digest = lib.Base58

Expand Down
Loading

0 comments on commit 6d19e12

Please sign in to comment.