Skip to content

Commit

Permalink
revamp deploySc.go
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Dec 3, 2024
1 parent 0f62eff commit 790dca2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions int/api/cmd/deploySC.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package cmd

import (
_ "embed"
"encoding/base64"
"io"
"strconv"

"github.com/go-openapi/runtime/middleware"
"github.com/massalabs/station/api/swagger/server/models"
Expand All @@ -13,6 +14,9 @@ import (
"github.com/massalabs/station/pkg/onchain"
)

//go:embed sc/deployer.wasm
var deployerSCByteCode []byte

func NewDeploySCHandler(config *config.NetworkInfos) operations.CmdDeploySCHandler {
return &deploySC{networkInfos: config}
}
Expand All @@ -22,45 +26,59 @@ type deploySC struct {
}

func (d *deploySC) Handle(params operations.CmdDeploySCParams) middleware.Responder {
file, err := io.ReadAll(params.SmartContract)
smartContractByteCode, err := base64.StdEncoding.DecodeString(params.Body.SmartContract)
if err != nil {
return operations.NewCmdDeploySCBadRequest().
return operations.NewCmdDeploySCInternalServerError().
WithPayload(
&models.Error{
Code: err.Error(),
Message: err.Error(),
})
}
/* All the pointers below cannot be null as the swagger hydrate
each one with their default value defined in swagger.yml,
if no values are provided for these parameters.
*/
decodedDatastore, err := base64.StdEncoding.DecodeString(*params.Datastore)

parameters, err := base64.StdEncoding.DecodeString(params.Body.Parameters)
if err != nil {
return operations.NewCmdDeploySCBadRequest().
return operations.NewCmdDeploySCInternalServerError().
WithPayload(
&models.Error{
Code: err.Error(),
Message: err.Error(),
})
}

if len(decodedDatastore) == 0 {
decodedDatastore = nil
maxCoins, err := strconv.ParseUint(*params.Body.MaxCoins, 10, 64)
if err != nil {
return operations.NewCmdDeploySCInternalServerError().
WithPayload(
&models.Error{
Code: err.Error(),
Message: err.Error(),
})
}

fees, err := strconv.ParseUint(*params.Body.Coins, 10, 64)
if err != nil {
return operations.NewCmdDeploySCInternalServerError().
WithPayload(
&models.Error{
Code: err.Error(),
Message: err.Error(),
})
}


operationResponse, events, err := onchain.DeploySC(
d.networkInfos,
params.WalletNickname,
*params.GasLimit,
*params.Coins,
*params.Fee,
*params.Expiry,
file,
decodedDatastore,
sendoperation.OperationBatch{NewBatch: false, CorrelationID: ""},
params.Body.Nickname,
sendoperation.MaxGasAllowedExecuteSC, // default
maxCoins, // maxCoins
fees, // smart contract deployment "fee"
sendoperation.DefaultExpiryInSlot,
parameters,
smartContractByteCode,
deployerSCByteCode,

Check failure on line 79 in int/api/cmd/deploySC.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

cannot use deployerSCByteCode (variable of type []byte) as sendoperation.OperationBatch value in argument to onchain.DeploySC

Check failure on line 79 in int/api/cmd/deploySC.go

View workflow job for this annotation

GitHub Actions / build / build and upload artifacts (ubuntu-latest, amd64, windows, x86_64-w64-mingw32-gcc, .exe)

cannot use deployerSCByteCode (variable of type []byte) as sendoperation.OperationBatch value in argument to onchain.DeploySC

Check failure on line 79 in int/api/cmd/deploySC.go

View workflow job for this annotation

GitHub Actions / test (macos-13)

cannot use deployerSCByteCode (variable of type []byte) as sendoperation.OperationBatch value in argument to onchain.DeploySC

Check failure on line 79 in int/api/cmd/deploySC.go

View workflow job for this annotation

GitHub Actions / build / build and upload artifacts (ubuntu-20.04, amd64, linux)

cannot use deployerSCByteCode (variable of type []byte) as sendoperation.OperationBatch value in argument to onchain.DeploySC

Check failure on line 79 in int/api/cmd/deploySC.go

View workflow job for this annotation

GitHub Actions / build / build and upload artifacts (macos-13, amd64, darwin)

cannot use deployerSCByteCode (variable of type []byte) as sendoperation.OperationBatch value in argument to onchain.DeploySC

Check failure on line 79 in int/api/cmd/deploySC.go

View workflow job for this annotation

GitHub Actions / build / build and upload artifacts (macos-13, arm64, darwin)

cannot use deployerSCByteCode (variable of type []byte) as sendoperation.OperationBatch value in argument to onchain.DeploySC
&signer.WalletPlugin{},
"",
"Deploying contract "+params.Body.Description,
)
if err != nil {
return operations.NewCmdDeploySCInternalServerError().
Expand Down
Binary file added int/api/cmd/sc/deployer.wasm
Binary file not shown.

0 comments on commit 790dca2

Please sign in to comment.