-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactore: move ika client to ika package (#36)
- Loading branch information
1 parent
4013cb8
commit f6c90fa
Showing
8 changed files
with
134 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
NATIVE_RPC=http://localhost:26657 | ||
NATIVE_GRPC=127.0.0.1:9090 | ||
LOG_FILE_PATH="" # If empty, logs to STDOUT | ||
LOG_LEVEL="debug" | ||
|
||
NATIVE_RPC=http://localhost:26657 | ||
NATIVE_GRPC=127.0.0.1:9090 | ||
|
||
IKA_RPC=http://127.0.0.1:9000 | ||
IKA_SIGNER_MNEMONIC="" | ||
GAS_ADDRESS="" | ||
IKA_GAS_ACC="" | ||
IKA_GAS_BUDGET="" | ||
IKA_NATIVE_LC_PACKAGE="" | ||
IKA_NATIVE_LC_MODULE="" | ||
IKA_NATIVE_LC_FUNCTION="" | ||
GAS_BUDGET="" | ||
|
||
BTC_RPC_USER="user" | ||
BTC_RPC_PASS="pass" | ||
BTC_RPC="localhost:18334" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package ika | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/block-vision/sui-go-sdk/models" | ||
"github.com/block-vision/sui-go-sdk/signer" | ||
"github.com/block-vision/sui-go-sdk/sui" | ||
tmtypes "github.com/cometbft/cometbft/types" | ||
"github.com/rs/zerolog" | ||
) | ||
|
||
// Client is a wrapper around the Sui client that provides functionality | ||
// for interacting with Ika | ||
type Client struct { | ||
c *sui.Client | ||
Signer *signer.Signer | ||
LcPackage string | ||
Module string | ||
Function string | ||
GasAddr string | ||
GasBudget string | ||
} | ||
|
||
// NewClient creates a new Client instance | ||
func NewClient( | ||
c *sui.Client, | ||
signer *signer.Signer, | ||
ctr SuiCtrCall, | ||
gasAddr, gasBudget string, | ||
) (*Client, error) { | ||
i := &Client{ | ||
c: c, | ||
Signer: signer, | ||
LcPackage: ctr.Package, | ||
Module: ctr.Module, | ||
Function: ctr.Function, | ||
GasAddr: gasAddr, | ||
GasBudget: gasBudget, | ||
} | ||
return i, nil | ||
} | ||
|
||
// UpdateLC sends light blocks to the Native Light Client module in the Ika blockchain. | ||
// It returns the transaction response and an error if any occurred. | ||
func (p *Client) UpdateLC( | ||
ctx context.Context, | ||
lb *tmtypes.LightBlock, | ||
logger zerolog.Logger, | ||
) (models.SuiTransactionBlockResponse, error) { | ||
req := models.MoveCallRequest{ | ||
Signer: p.Signer.Address, | ||
PackageObjectId: p.LcPackage, | ||
Module: p.Module, | ||
Function: p.Function, | ||
TypeArguments: []interface{}{}, | ||
Arguments: []interface{}{ | ||
lb, | ||
}, | ||
Gas: p.GasAddr, | ||
GasBudget: p.GasBudget, | ||
} | ||
resp, err := p.c.MoveCall(ctx, req) | ||
if err != nil { | ||
logger.Err(err).Msg("Error calling move function:") | ||
return models.SuiTransactionBlockResponse{}, err // Return zero value for the response | ||
} | ||
|
||
// TODO: verify if we need to call this | ||
return p.c.SignAndExecuteTransactionBlock(ctx, models.SignAndExecuteTransactionBlockRequest{ | ||
TxnMetaData: resp, | ||
PriKey: p.Signer.PriKey, | ||
Options: models.SuiTransactionBlockOptions{ | ||
ShowInput: true, | ||
ShowRawInput: true, | ||
ShowEffects: true, | ||
}, | ||
RequestType: "WaitForLocalExecution", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ika | ||
|
||
import ( | ||
"errors" | ||
"strings" | ||
) | ||
|
||
// SuiCtrCall defines a contract path to call in Sui | ||
type SuiCtrCall struct { | ||
Package, Module, Function string | ||
} | ||
|
||
// Validate the fields of the struct | ||
func (ctr SuiCtrCall) Validate() error { | ||
return errors.Join( | ||
checkNotEmpty("package", ctr.Package), | ||
checkNotEmpty("module", ctr.Module), | ||
checkNotEmpty("function", ctr.Function), | ||
) | ||
} | ||
|
||
func checkNotEmpty(name, s string) error { | ||
if strings.TrimSpace(s) == "" { | ||
return errors.New(name + " must be defined") | ||
} | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.