-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add deploy Sc #1370
Closed
Closed
add deploy Sc #1370
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
3c7f7e1
add deploy Sc
pivilartisant 2a30913
fmt
pivilartisant a6e2704
add better datastore
pivilartisant 2de2485
add correct datastore
pivilartisant 027ba18
add serialized datastore and clean executeSC.message() method
pivilartisant 9f81288
fix smart contract byteCode
pivilartisant c5b53b3
remove legacy operationBatch param
pivilartisant 7c9d36b
fmt
pivilartisant f7e54b4
add revise datastore serialization
pivilartisant 794e772
add hardcoded args and coins key
pivilartisant a5c90cc
Revert "fmt"
pivilartisant 628c764
fmt
pivilartisant a59620c
review-changes
pivilartisant fb7b0a9
add fmt
pivilartisant 35f9892
fmt
pivilartisant 9857de3
add pkg json fmt
pivilartisant 7ce8f39
updat package lock
pivilartisant 25ebf03
remove package.lock
pivilartisant e5452cf
correct packagelock
pivilartisant 3fd6284
fix prettier dep
pivilartisant 7add6a9
fmt
pivilartisant 9acdd97
remove pkg
pivilartisant 8139349
add pkg lock
pivilartisant 505ca4c
remove prettier from web fmt
pivilartisant 54db9dc
bump wallet provider
pivilartisant 455e4e7
remove wallet privide
pivilartisant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package cmd | ||
|
||
import ( | ||
"bytes" | ||
_ "embed" | ||
"encoding/base64" | ||
"io" | ||
|
||
|
@@ -13,6 +15,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} | ||
} | ||
|
@@ -22,7 +27,9 @@ type deploySC struct { | |
} | ||
|
||
func (d *deploySC) Handle(params operations.CmdDeploySCParams) middleware.Responder { | ||
file, err := io.ReadAll(params.SmartContract) | ||
_smartContractBytes, err := base64.StdEncoding.DecodeString(params.Body.SmartContract) | ||
smartContractReader := bytes.NewReader(_smartContractBytes) | ||
smartContractByteCode, err := io.ReadAll(smartContractReader) | ||
pivilartisant marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return operations.NewCmdDeploySCBadRequest(). | ||
WithPayload( | ||
|
@@ -31,11 +38,10 @@ func (d *deploySC) Handle(params operations.CmdDeploySCParams) middleware.Respon | |
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) | ||
parameterReader := bytes.NewReader(_parameters) | ||
parameters, err := io.ReadAll(parameterReader) | ||
Comment on lines
+42
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as before |
||
if err != nil { | ||
return operations.NewCmdDeploySCBadRequest(). | ||
WithPayload( | ||
|
@@ -45,22 +51,18 @@ func (d *deploySC) Handle(params operations.CmdDeploySCParams) middleware.Respon | |
}) | ||
} | ||
|
||
if len(decodedDatastore) == 0 { | ||
decodedDatastore = nil | ||
} | ||
|
||
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 | ||
*params.Body.MaxCoins, // maxCoins | ||
*params.Body.Coins, // smart contract deployment "fee" | ||
sendoperation.DefaultExpiryInSlot, | ||
parameters, | ||
smartContractByteCode, | ||
deployerSCByteCode, | ||
&signer.WalletPlugin{}, | ||
"", | ||
"Deploying contract "+params.Body.Description, | ||
) | ||
if err != nil { | ||
return operations.NewCmdDeploySCInternalServerError(). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,14 @@ import ( | |
"context" | ||
b64 "encoding/base64" | ||
"encoding/binary" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/massalabs/station/pkg/convert" | ||
"github.com/massalabs/station/pkg/logger" | ||
"github.com/massalabs/station/pkg/node" | ||
"github.com/massalabs/station/pkg/node/base58" | ||
"github.com/massalabs/station/pkg/node/sendoperation/signer" | ||
|
@@ -42,11 +46,6 @@ type OperationResponse struct { | |
CorrelationID string | ||
} | ||
|
||
type OperationBatch struct { | ||
NewBatch bool | ||
CorrelationID string | ||
} | ||
|
||
type JSONableSlice []uint8 | ||
|
||
func (u JSONableSlice) MarshalJSON() ([]byte, error) { | ||
|
@@ -69,7 +68,6 @@ func Call( | |
fee uint64, | ||
operation Operation, | ||
nickname string, | ||
operationBatch OperationBatch, | ||
signer signer.Signer, | ||
description string, | ||
) (*OperationResponse, error) { | ||
|
@@ -78,7 +76,8 @@ func Call( | |
return nil, err | ||
} | ||
|
||
content := createOperationContent(operationBatch, description, msgB64, chainID) | ||
content := createOperationContent(description, msgB64, chainID) | ||
logger.Infof("json content: %v",content) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to delete |
||
|
||
res, err := signer.Sign(nickname, []byte(content)) | ||
if err != nil { | ||
|
@@ -105,24 +104,19 @@ 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 | ||
|
||
const descriptionLabel = `{"description": "` | ||
func createOperationContent(description string, msgB64 string, chainID uint64) string { | ||
data := map[string]interface{}{ | ||
"description": description, | ||
"operation": msgB64, | ||
"chainId": strconv.FormatUint(chainID, 10), | ||
} | ||
|
||
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, err := json.Marshal(data) | ||
if err != nil { | ||
log.Fatalf("Error marshaling JSON: %v", err) | ||
} | ||
|
||
return content | ||
return convert.ToString(content) | ||
} | ||
|
||
func MakeRPCCall(msg []byte, signature []byte, publicKey string, client *node.Client) ([]string, error) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should not use "integer" type for MAS amount, but string. (same for fee).
Because json number cannot handle of range of uint64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so that would concern fee, maxCoins & coins fields ?