Skip to content
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

feat(ioctl): support znode project management commands(based #3987) #3989

Merged
merged 22 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
27f9da0
feat(ioctl): add znode commands configs
saitofun Nov 21, 2023
cdef48b
feat(ioctl): add znode commands configs
saitofun Nov 21, 2023
fda9ccb
Merge branch 'feat/support_znode_config' of github.com:iotexproject/i…
saitofun Nov 21, 2023
0c3a360
feat(ioctl): support znode message committing and querying commands(b…
saitofun Nov 21, 2023
1ff3a81
chore: code fmt
saitofun Nov 21, 2023
8d0c554
draft
saitofun Nov 21, 2023
745d278
Merge branch 'master' of github.com:iotexproject/iotex-core into feat…
saitofun Nov 22, 2023
937a89d
feat(ioctl): support ws project mgr commands
saitofun Nov 23, 2023
7c9b35a
feat(ioctl): support w3bstream message committing and querying comman…
saitofun Nov 24, 2023
6fdea63
Merge branch 'master' of github.com:iotexproject/iotex-core into feat…
saitofun Nov 24, 2023
869306a
Merge branch 'feat/ioctl_znode_message_query' of github.com:iotexproj…
saitofun Nov 24, 2023
ae56452
feat(ioctl): ws node project management
saitofun Nov 24, 2023
a2ece84
Merge branch 'master' into feat/ioctl_znode_project
CoderZhi Nov 27, 2023
27326ff
Merge branch 'master' of github.com:iotexproject/iotex-core into feat…
saitofun Nov 27, 2023
3f361c3
feat(ioctl): ws node project management
saitofun Nov 27, 2023
34d1446
Merge branch 'feat/ioctl_znode_project' of github.com:iotexproject/io…
saitofun Nov 27, 2023
2f270a5
feat(ioctl): ws node project management
saitofun Nov 27, 2023
4e54f80
feat(ioctl): ws node project management
saitofun Nov 27, 2023
8db7976
feat(ioctl): ws node project management
saitofun Nov 27, 2023
3d4a771
feat(ioctl): ws node project management
saitofun Nov 28, 2023
f1335e4
feat(ioctl): ws node project management
saitofun Nov 28, 2023
5f8d6b9
Merge branch 'master' of github.com:iotexproject/iotex-core into feat…
saitofun Nov 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 54 additions & 36 deletions ioctl/cmd/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,26 +212,6 @@ func fixGasLimit(caller string, execution *action.Execution) (*action.Execution,

// SendRaw sends raw action to blockchain
func SendRaw(selp *iotextypes.Action) error {
conn, err := util.ConnectToEndpoint(config.ReadConfig.SecureConnect && !config.Insecure)
saitofun marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return output.NewError(output.NetworkError, "failed to connect to endpoint", err)
}
defer conn.Close()
cli := iotexapi.NewAPIServiceClient(conn)
ctx := context.Background()

jwtMD, err := util.JwtAuth()
if err == nil {
ctx = metautils.NiceMD(jwtMD).ToOutgoing(ctx)
}

request := &iotexapi.SendActionRequest{Action: selp}
if _, err = cli.SendAction(ctx, request); err != nil {
if sta, ok := status.FromError(err); ok {
return output.NewError(output.APIError, sta.Message(), nil)
}
return output.NewError(output.NetworkError, "failed to invoke SendAction api", err)
}
shash := hash.Hash256b(byteutil.Must(proto.Marshal(selp)))
txhash := hex.EncodeToString(shash[:])
message := sendMessage{Info: "Action has been sent to blockchain.", TxHash: txhash, URL: "https://"}
Expand All @@ -250,16 +230,48 @@ func SendRaw(selp *iotextypes.Action) error {
return nil
}

// SendRawAndRespond sends raw action to blockchain with response and error return
func SendRawAndRespond(selp *iotextypes.Action) (*iotexapi.SendActionResponse, error) {
conn, err := util.ConnectToEndpoint(config.ReadConfig.SecureConnect && !config.Insecure)
if err != nil {
return nil, output.NewError(output.NetworkError, "failed to connect to endpoint", err)
}
defer conn.Close()
cli := iotexapi.NewAPIServiceClient(conn)
ctx := context.Background()

jwtMD, err := util.JwtAuth()
if err == nil {
ctx = metautils.NiceMD(jwtMD).ToOutgoing(ctx)
}

request := &iotexapi.SendActionRequest{Action: selp}
response, err := cli.SendAction(ctx, request)
if err != nil {
if sta, ok := status.FromError(err); ok {
return nil, output.NewError(output.APIError, sta.Message(), nil)
}
return nil, output.NewError(output.NetworkError, "failed to invoke SendAction api", err)
}
return response, nil
}

// SendAction sends signed action to blockchain
func SendAction(elp action.Envelope, signer string) error {
_, err := SendActionAndResponse(elp, signer)
return err
}

// SendActionAndResponse sends signed action to blockchain with response and error return
func SendActionAndResponse(elp action.Envelope, signer string) (*iotexapi.SendActionResponse, error) {
prvKey, err := account.PrivateKeyFromSigner(signer, _passwordFlag.Value().(string))
if err != nil {
return err
return nil, err
}

chainMeta, err := bc.GetChainMeta()
if err != nil {
return output.NewError(0, "failed to get chain meta", err)
return nil, output.NewError(0, "failed to get chain meta", err)
}
elp.SetChainID(chainMeta.GetChainID())

Expand All @@ -268,24 +280,24 @@ func SendAction(elp action.Envelope, signer string) error {
signer = addr.String()
nonce, err := nonce(signer)
if err != nil {
return output.NewError(0, "failed to get nonce ", err)
return nil, output.NewError(0, "failed to get nonce ", err)
}
elp.SetNonce(nonce)
}

sealed, err := action.Sign(elp, prvKey)
prvKey.Zero()
if err != nil {
return output.NewError(output.CryptoError, "failed to sign action", err)
return nil, output.NewError(output.CryptoError, "failed to sign action", err)
}
if err := isBalanceEnough(signer, sealed); err != nil {
return output.NewError(0, "failed to pass balance check", err) // TODO: undefined error
return nil, output.NewError(0, "failed to pass balance check", err) // TODO: undefined error
}

selp := sealed.Proto()
actionInfo, err := printActionProto(selp)
if err != nil {
return output.NewError(0, "failed to print action proto message", err)
return nil, output.NewError(0, "failed to print action proto message", err)
}

if _yesFlag.Value() == false {
Expand All @@ -295,47 +307,53 @@ func SendAction(elp action.Envelope, signer string) error {
fmt.Println(message.String())

if _, err := fmt.Scanf("%s", &confirm); err != nil {
return output.NewError(output.InputError, "failed to input yes", err)
return nil, output.NewError(output.InputError, "failed to input yes", err)
}
if !strings.EqualFold(confirm, "yes") {
output.PrintResult("quit")
return nil
return nil, nil
}
}

return SendRaw(selp)
return SendRawAndRespond(selp)
}

// Execute sends signed execution transaction to blockchain
func Execute(contract string, amount *big.Int, bytecode []byte) error {
_, err := ExecuteAndResponse(contract, amount, bytecode)
return err
}

// ExecuteAndResponse sends signed execution transaction to blockchain and with response and error return
func ExecuteAndResponse(contract string, amount *big.Int, bytecode []byte) (*iotexapi.SendActionResponse, error) {
if len(contract) == 0 && len(bytecode) == 0 {
return output.NewError(output.InputError, "failed to deploy contract with empty bytecode", nil)
return nil, output.NewError(output.InputError, "failed to deploy contract with empty bytecode", nil)
}
gasPriceRau, err := gasPriceInRau()
if err != nil {
return output.NewError(0, "failed to get gas price", err)
return nil, output.NewError(0, "failed to get gas price", err)
}
signer, err := Signer()
if err != nil {
return output.NewError(output.AddressError, "failed to get signer address", err)
return nil, output.NewError(output.AddressError, "failed to get signer address", err)
}
nonce, err := nonce(signer)
if err != nil {
return output.NewError(0, "failed to get nonce", err)
return nil, output.NewError(0, "failed to get nonce", err)
}
gasLimit := _gasLimitFlag.Value().(uint64)
tx, err := action.NewExecution(contract, nonce, amount, gasLimit, gasPriceRau, bytecode)
if err != nil || tx == nil {
return output.NewError(output.InstantiationError, "failed to make a Execution instance", err)
return nil, output.NewError(output.InstantiationError, "failed to make a Execution instance", err)
}
if gasLimit == 0 {
tx, err = fixGasLimit(signer, tx)
if err != nil || tx == nil {
return output.NewError(0, "failed to fix Execution gaslimit", err)
return nil, output.NewError(0, "failed to fix Execution gaslimit", err)
}
gasLimit = tx.GasLimit()
}
return SendAction(
return SendActionAndResponse(
(&action.EnvelopeBuilder{}).
SetNonce(nonce).
SetGasPrice(gasPriceRau).
Expand Down
Loading
Loading