Skip to content

Commit

Permalink
fix content formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pivilartisant committed Dec 4, 2024
1 parent d288070 commit 9e0b457
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
1 change: 0 additions & 1 deletion api/swagger/server/restapi/resource/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ paths:
parameters:
description: Base64 encoded parameters that will be sent along the smart contract.
type: string
default: ""
description:
description: "Description of the operation"
type: string
Expand Down
10 changes: 5 additions & 5 deletions int/api/cmd/deploySC.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (d *deploySC) Handle(params operations.CmdDeploySCParams) middleware.Respon
Message: err.Error(),
})
}

parameters, err := base64.StdEncoding.DecodeString(params.Body.Parameters)
if err != nil {
return operations.NewCmdDeploySCInternalServerError().
Expand All @@ -56,7 +56,7 @@ func (d *deploySC) Handle(params operations.CmdDeploySCParams) middleware.Respon
})
}

fees, err := strconv.ParseUint(*params.Body.Coins, 10, 64)
coins, err := strconv.ParseUint(*params.Body.Coins, 10, 64)
if err != nil {
return operations.NewCmdDeploySCInternalServerError().
WithPayload(
Expand All @@ -65,19 +65,19 @@ func (d *deploySC) Handle(params operations.CmdDeploySCParams) middleware.Respon
Message: err.Error(),
})
}

operationResponse, events, err := onchain.DeploySC(
d.networkInfos,
params.Body.Nickname,
sendoperation.MaxGasAllowedExecuteSC, // default
maxCoins, // maxCoins
fees, // smart contract deployment "fee"
coins, // smart contract deployment "fee"
sendoperation.DefaultExpiryInSlot,
parameters,
smartContractByteCode,
deployerSCByteCode,
&signer.WalletPlugin{},
"Deploying contract "+params.Body.Description,
"Deploying contract" + *params.Body.Description,

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

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

invalid operation: cannot indirect params.Body.Description (variable of type string)

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

View workflow job for this annotation

GitHub Actions / test (macos-13)

invalid operation: cannot indirect params.Body.Description (variable of type string)

Check failure on line 80 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)

invalid operation: cannot indirect params.Body.Description (variable of type string)

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

View workflow job for this annotation

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

invalid operation: cannot indirect params.Body.Description (variable of type string)
)
if err != nil {
return operations.NewCmdDeploySCInternalServerError().
Expand Down
31 changes: 19 additions & 12 deletions pkg/node/sendoperation/sendoperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
"log"
"strconv"
"strings"

"github.com/massalabs/station/pkg/convert"
"github.com/massalabs/station/pkg/node"
"github.com/massalabs/station/pkg/node/base58"
"github.com/massalabs/station/pkg/node/sendoperation/signer"
Expand Down Expand Up @@ -45,6 +42,13 @@ type OperationResponse struct {
CorrelationID string
}

type OperationContent struct {
Description string `json:"description"`
Operation string `json:"operation"`
ChainID uint64 `json:"chainId"`
}


type JSONableSlice []uint8

func (u JSONableSlice) MarshalJSON() ([]byte, error) {
Expand Down Expand Up @@ -75,7 +79,10 @@ func Call(
return nil, err
}

content := createOperationContent(description, msgB64, chainID)
content, err := createOperationContent(description, msgB64, chainID)
if err != nil {
return nil, fmt.Errorf("creating operation content: %w", err)
}

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

func createOperationContent(description string, msgB64 string, chainID uint64) string {
data := map[string]interface{}{
"description": description,
"operation": msgB64,
"chainId": strconv.FormatUint(chainID, 10),
func createOperationContent(description string, msgB64 string, chainID uint64) (string, error) {
operationContent := OperationContent{
Description: description,
Operation: msgB64,
ChainID: chainID,
}

content, err := json.Marshal(data)
jsonContent, err := json.Marshal(operationContent)
if err != nil {
log.Fatalf("Error marshaling JSON: %v", err)
return "", fmt.Errorf("marshalling operation content: %w", err)
}

return convert.ToString(content)
return string(jsonContent), nil
}

func MakeRPCCall(msg []byte, signature []byte, publicKey string, client *node.Client) ([]string, error) {
Expand Down

0 comments on commit 9e0b457

Please sign in to comment.