Skip to content

Commit

Permalink
remove legacy operationBatch param
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Nov 29, 2024
1 parent 9f81288 commit c5b53b3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 30 deletions.
19 changes: 14 additions & 5 deletions int/api/cmd/deploySC.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ type deploySC struct {
}

func (d *deploySC) Handle(params operations.CmdDeploySCParams) middleware.Responder {
// smart contract deployer bytes code


// smart contract bytes code
_smartContractBytes, err := base64.StdEncoding.DecodeString(params.Body.SmartContract)
smartContractReader := bytes.NewReader(_smartContractBytes)
smartContractByteCode, err := io.ReadAll(smartContractReader)
Expand All @@ -42,17 +39,29 @@ func (d *deploySC) Handle(params operations.CmdDeploySCParams) middleware.Respon
Message: err.Error(),
})
}

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

operationResponse, events, err := onchain.DeploySC(
d.networkInfos,
params.Body.Nickname,
sendoperation.MaxGasAllowedExecuteSC,
*params.Body.MaxCoins, // maxCoins
*params.Body.Coins, // smart contract deployment cost
sendoperation.DefaultExpiryInSlot,
[]byte{}, // TODO add smart contract parameters
parameters,
smartContractByteCode,
deployerSCByteCode,
sendoperation.OperationBatch{NewBatch: false, CorrelationID: ""},
&signer.WalletPlugin{},
"Deploying website",
)
Expand Down
1 change: 0 additions & 1 deletion int/api/cmd/execute_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func (e *executeFunction) Handle(params operations.CmdExecuteFunctionParams) mid
uint64(params.Body.Coins),
expiry,
asyncReq,
sendOperation.OperationBatch{NewBatch: false, CorrelationID: ""},
&signer.WalletPlugin{},
params.Body.Description,
)
Expand Down
23 changes: 5 additions & 18 deletions pkg/node/sendoperation/sendoperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ type OperationResponse struct {
CorrelationID string
}

type OperationBatch struct {
NewBatch bool
CorrelationID string
}

type JSONableSlice []uint8

Expand All @@ -69,7 +65,6 @@ func Call(
fee uint64,
operation Operation,
nickname string,
operationBatch OperationBatch,
signer signer.Signer,
description string,
) (*OperationResponse, error) {
Expand All @@ -78,7 +73,7 @@ func Call(
return nil, err
}

content := createOperationContent(operationBatch, description, msgB64, chainID)
content := createOperationContent( description, msgB64, chainID)

res, err := signer.Sign(nickname, []byte(content))
if err != nil {
Expand All @@ -105,22 +100,14 @@ func Call(
return &OperationResponse{CorrelationID: res.CorrelationID, OperationID: resp[0]}, nil
}

func createOperationContent(operationBatch OperationBatch, description string, msgB64 string, chainID uint64) string {
func createOperationContent(description string, msgB64 string, chainID uint64) string {
var content string

const descriptionLabel = `{"description": "`

switch {
case operationBatch.NewBatch:
content = descriptionLabel + description + `", "operation": "` + msgB64 + `",
"batch": true, "chainId": ` + strconv.FormatUint(chainID, 10) + `}`
case operationBatch.CorrelationID != "":
content = descriptionLabel + description + `", "operation": "` + msgB64 + `",
"correlationId": "` + operationBatch.CorrelationID + `", "chainId": ` + strconv.FormatUint(chainID, 10) + `}`
default:
content = descriptionLabel + description + `",
"operation": "` + msgB64 + `", "chainId": ` + strconv.FormatUint(chainID, 10) + `}`
}
content = descriptionLabel + description + `",
"operation": "` + msgB64 + `", "chainId": ` + strconv.FormatUint(chainID, 10) + `}`


return content
}
Expand Down
6 changes: 0 additions & 6 deletions pkg/onchain/sc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/massalabs/station/int/config"
"github.com/massalabs/station/pkg/logger"
"github.com/massalabs/station/pkg/node"
sendOperation "github.com/massalabs/station/pkg/node/sendoperation"
"github.com/massalabs/station/pkg/node/sendoperation/callsc"
Expand All @@ -33,7 +32,6 @@ func CallFunction(
coins uint64,
expiryDelta uint64,
async bool,
operationBatch sendOperation.OperationBatch,
signer signer.Signer,
description string,
) (*OperationWithEventResponse, error) {
Expand Down Expand Up @@ -64,7 +62,6 @@ func CallFunction(
fee,
callSC,
nickname,
operationBatch,
signer,
description,
)
Expand Down Expand Up @@ -118,13 +115,11 @@ func DeploySC(
parameters []byte,
smartContractByteCode []byte,
deployerByteCode []byte,
operationBatch sendOperation.OperationBatch,
signer signer.Signer,
description string,
) (*sendOperation.OperationResponse, []node.Event, error) {
client := node.NewClient(networkInfos.NodeURL)

logger.Infof("smartContractBytecode length %v", len(smartContractByteCode))
contract := DatastoreContract{
Data: smartContractByteCode,
Args: parameters,
Expand All @@ -150,7 +145,6 @@ func DeploySC(
fees,
exeSCOperation,
nickname,
operationBatch,
signer,
"Deploying smart contract: "+description,
)
Expand Down

0 comments on commit c5b53b3

Please sign in to comment.