Skip to content

Commit

Permalink
Refactor following minimal fees (#1344)
Browse files Browse the repository at this point in the history
* refactor Call: add func createOperationContent

* fix a comment in swagger
  • Loading branch information
Thykof authored Apr 17, 2024
1 parent 412f541 commit 89f8088
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion api/swagger/server/restapi/resource/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ paths:
type : integer
minimum: 0
format: uint64
description: Set the fee amount (in massa) that will be given to the block creator.
description: Set the fee amount (in nanoMassa) that will be given to the block creator.
default : 0
- in: formData
name: datastore
Expand Down
40 changes: 23 additions & 17 deletions pkg/node/sendoperation/sendoperation.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,23 +78,7 @@ func Call(
return nil, err
}

var content string

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

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

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

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

return content
}

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

0 comments on commit 89f8088

Please sign in to comment.