Skip to content

Commit

Permalink
revamp sc.go
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Dec 3, 2024
1 parent b7bca9f commit 50ce8c9
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions pkg/onchain/sc.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,45 +104,48 @@ func CallFunctionSuccess(

// DeploySC deploys a smart contract on the blockchain.
// The smart contract is deployed with the given account nickname.

func DeploySC(
networkInfos *config.NetworkInfos,
nickname string,
maxGas uint64,
maxCoins uint64,
fee uint64,
fees uint64,
expiry uint64,
contract []byte,
datastore []byte,
parameters []byte,
smartContractByteCode []byte,
deployerByteCode []byte,
signer signer.Signer,
description string,
) (*sendOperation.OperationResponse, []node.Event, error) {
client := node.NewClient(networkInfos.NodeURL)

// Calibrate max_gas
if maxGas == 0 {
estimatedGasCost, err := sendOperation.EstimateGasCostExecuteSC(nickname, contract, datastore, maxCoins, fee, client)
if err != nil {
return nil, nil, fmt.Errorf("estimating Execute SC gas cost: %w", err)
}
contract := ContractDatastore{
Data: smartContractByteCode,
Args: parameters,
Coins: fees,
}

maxGas = estimatedGasCost
dataStore, err := populateDatastore(contract)
if err != nil {
return nil, nil, fmt.Errorf("populating datastore: %w", err)
}

exeSC := executesc.New(
contract,
exeSCOperation := executesc.New(
deployerByteCode,
maxGas,
maxCoins,
datastore)
dataStore)

operationResponse, err := sendOperation.Call(
client,
networkInfos.ChainID,
expiry,
fee,
exeSC,
fees,
exeSCOperation,
nickname,
signer,
"Deploying smart contract: "+description,
description,
)
if err != nil {
return nil, nil, fmt.Errorf("calling executeSC: %w", err)
Expand Down

0 comments on commit 50ce8c9

Please sign in to comment.