Skip to content

Commit

Permalink
fix: format code
Browse files Browse the repository at this point in the history
  • Loading branch information
BarryTong65 committed Apr 18, 2024
1 parent efb81c0 commit aaa1b4c
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 313 deletions.
22 changes: 11 additions & 11 deletions bsc/api_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ func (c *Client) GetMinAckRelayFee(ctx context.Context) (relayFee *big.Int, minA
)
parsedABI, err := abi.JSON(strings.NewReader(bsccommon.CrossChainABI))
if err != nil {
log.Fatalf("Failed to parse contract ABI: %v", err)
log.Fatalf("failed to parse contract ABI: %v", err)
}

packedData, err := parsedABI.Pack("getRelayFees")
if err != nil {
log.Fatalf("Failed to pack data for sendMessages: %v", err)
log.Fatalf("failed to pack data for getRelayFees: %v", err)
}

contractAddress := common.HexToAddress(c.GetDeployment().CrossChain)
Expand All @@ -93,22 +93,22 @@ func (c *Client) GetMinAckRelayFee(ctx context.Context) (relayFee *big.Int, minA

resp, err := c.chainClient.CallContract(ctx, msg, nil)
if err != nil {
log.Fatalf("Failed to call contract: %v", err)
log.Fatalf("failed to call contract: %v", err)
}

result, err := parsedABI.Unpack("getRelayFees", resp)
if err != nil {
log.Fatalf("Failed to unpack returned data: %v", err)
log.Fatalf("failed to unpack returned data: %v", err)
}

if len(result) != 2 {
log.Fatalf("Expected two return values from getRelayFees")
log.Fatalf("expected two return values from getRelayFees")
}

relayFee, ok1 = result[0].(*big.Int)
minAckRelayFee, ok2 = result[1].(*big.Int)
if !ok1 || !ok2 {
log.Fatalf("Type assertion failed for one or both return values")
log.Fatalf("type assertion failed for one or both return values")
}

return relayFee, minAckRelayFee, nil
Expand All @@ -120,12 +120,12 @@ func (c *Client) GetCallbackGasPrice(ctx context.Context) (gasPrice *big.Int, er
)
parsedABI, err := abi.JSON(strings.NewReader(bsccommon.CrossChainABI))
if err != nil {
log.Fatalf("Failed to parse contract ABI: %v", err)
log.Fatalf("failed to parse contract ABI: %v", err)
}

packedData, err := parsedABI.Pack("callbackGasPrice")
if err != nil {
log.Fatalf("Failed to pack data for sendMessages: %v", err)
log.Fatalf("failed to pack data for callbackGasPrice: %v", err)
}

contractAddress := common.HexToAddress(c.GetDeployment().CrossChain)
Expand All @@ -136,12 +136,12 @@ func (c *Client) GetCallbackGasPrice(ctx context.Context) (gasPrice *big.Int, er

resp, err := c.chainClient.CallContract(ctx, msg, nil)
if err != nil {
log.Fatalf("Failed to call contract: %v", err)
log.Fatalf("failed to call contract: %v", err)
}

result, err := parsedABI.Unpack("callbackGasPrice", resp)
if err != nil {
log.Fatalf("Failed to unpack returned data: %v", err)
log.Fatalf("failed to unpack returned data: %v", err)
}

if len(result) != 1 {
Expand All @@ -150,7 +150,7 @@ func (c *Client) GetCallbackGasPrice(ctx context.Context) (gasPrice *big.Int, er

gasPrice, ok = result[0].(*big.Int)
if !ok {
log.Fatalf("Type assertion failed for one or both return values")
log.Fatalf("type assertion failed for one or both return values")
}

return gasPrice, nil
Expand Down
6 changes: 3 additions & 3 deletions bsc/api_greenfield_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ type IGreenfieldExecutorClient interface {
func (c *Client) Execute(ctx context.Context, message *bsctypes.ExecutorMessages) (*common.Hash, error) {
parsedABI, err := abi.JSON(strings.NewReader(bsccommon.ExecutorABI))
if err != nil {
log.Fatalf("Failed to parse contract ABI: %v", err)
log.Fatalf("failed to parse contract ABI: %v", err)
}

packedData, err := parsedABI.Pack("execute", message.MsgTypes, message.MsgBytes)
if err != nil {
log.Fatalf("Failed to pack data for Execute: %v", err)
log.Fatalf("failed to pack data for execute: %v", err)
}

contractAddress := common.HexToAddress(c.GetDeployment().GreenfieldExecutor)
tx, err := c.SendTx(ctx, 0, &contractAddress, message.RelayFee, nil, packedData)
if err != nil {
log.Fatalf("Failed to call contract: %v", err)
log.Fatalf("failed to call contract: %v", err)
}

return tx, nil
Expand Down
6 changes: 3 additions & 3 deletions bsc/api_multi_messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ type IMultiMessageClient interface {
func (c *Client) SendMessages(ctx context.Context, message *bsctypes.MultiMessage) (*common.Hash, error) {
parsedABI, err := abi.JSON(strings.NewReader(bsccommon.MultiMessageABI))
if err != nil {
log.Fatalf("Failed to parse contract ABI: %v", err)
log.Fatalf("failed to parse contract ABI: %v", err)
}

packedData, err := parsedABI.Pack("sendMessages", message.Targets, message.Data, message.Values)
if err != nil {
log.Fatalf("Failed to pack data for sendMessages: %v", err)
log.Fatalf("failed to pack data for sendMessages: %v", err)
}

sum := new(big.Int)
Expand All @@ -36,7 +36,7 @@ func (c *Client) SendMessages(ctx context.Context, message *bsctypes.MultiMessag
contractAddress := common.HexToAddress(c.GetDeployment().MultiMessage)
tx, err := c.SendTx(ctx, 0, &contractAddress, sum, nil, packedData)
if err != nil {
log.Fatalf("Failed to call contract: %v", err)
log.Fatalf("failed to call contract: %v", err)
}

return tx, nil
Expand Down
18 changes: 5 additions & 13 deletions bsc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/bnb-chain/greenfield-go-sdk/bsctypes"
)

// IClient - Declare all Greenfield SDK Client APIs, including APIs for interacting with Greenfield Blockchain and SPs.
// IClient - Declare all BSC SDK Client APIs, including APIs for multi messages & greenfield executor
type IClient interface {
IMultiMessageClient
IGreenfieldExecutorClient
Expand All @@ -32,15 +32,7 @@ type Client struct {
// Whether the connection to the blockchain node is secure (HTTPS) or not (HTTP).
secure bool
// Host is the target sp server hostname,it is the host info in the request which sent to SP
host string
// The user agent info
//userAgent string
// define if trace the error request to BSC
//isTraceEnabled bool
//traceOutput io.Writer
//onlyTraceError bool
//useWebsocketConn bool
//expireSeconds uint64
host string
rpcURL string
deployment *bsctypes.Deployment
}
Expand Down Expand Up @@ -87,20 +79,20 @@ func New(rpcURL string, env string, option Option) (IClient, error) {

jsonFile, err := os.Open(path)
if err != nil {
log.Fatalf("Failed to open JSON file: %v", err)
log.Fatalf("failed to open JSON file: %v", err)
}
defer jsonFile.Close()

// Read the JSON file into a byte slice
byteValue, err := io.ReadAll(jsonFile)
if err != nil {
log.Fatalf("Failed to read JSON file: %v", err)
log.Fatalf("failed to read JSON file: %v", err)
return nil, err
}

err = json.Unmarshal(byteValue, &deployment)
if err != nil {
log.Fatalf("Failed to unmarshal JSON data: %v", err)
log.Fatalf("failed to unmarshal JSON data: %v", err)
return nil, err
}

Expand Down
189 changes: 0 additions & 189 deletions bsc_examples/multi_messages.go

This file was deleted.

File renamed without changes.
File renamed without changes.
Loading

0 comments on commit aaa1b4c

Please sign in to comment.