Skip to content

Commit

Permalink
Merge branch 'master' into opt_api_receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderZhi authored Apr 8, 2024
2 parents 8fcd84e + 3b9e91f commit f664e2f
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 6 deletions.
6 changes: 3 additions & 3 deletions api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ func (core *coreService) readState(ctx context.Context, p protocol.Protocol, hei
return d, h, err
}

func (core *coreService) getActionsFromIndex(totalActions, start, count uint64) ([]*iotexapi.ActionInfo, error) {
func (core *coreService) getActionsFromIndex(start, count uint64) ([]*iotexapi.ActionInfo, error) {
hashes, err := core.indexer.GetActionHashFromIndex(start, count)
if err != nil {
return nil, status.Error(codes.Unavailable, err.Error())
Expand Down Expand Up @@ -994,14 +994,14 @@ func (core *coreService) Actions(start uint64, count uint64) ([]*iotexapi.Action
if start >= totalActions {
return nil, status.Error(codes.InvalidArgument, "start exceeds the total actions in the block")
}
if totalActions == uint64(0) || count == 0 {
if totalActions == uint64(0) {
return []*iotexapi.ActionInfo{}, nil
}
if start+count > totalActions {
count = totalActions - start
}
if core.indexer != nil {
return core.getActionsFromIndex(totalActions, start, count)
return core.getActionsFromIndex(start, count)
}
// Finding actions in reverse order saves time for querying most recent actions
reverseStart := totalActions - (start + count)
Expand Down
4 changes: 4 additions & 0 deletions blockchain/blockdao/blockindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ func (bic *BlockIndexerChecker) CheckIndexer(ctx context.Context, indexer BlockI
}
}
for i := startHeight; i <= targetHeight; i++ {
// ternimate if context is done
if err := ctx.Err(); err != nil {
return errors.Wrap(err, "terminate the indexer checking")
}
blk, err := bic.dao.GetBlockByHeight(i)
if err != nil {
return err
Expand Down
7 changes: 5 additions & 2 deletions ioctl/cmd/action/stake2.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ import (
var (
_stake2CmdShorts = map[config.Language]string{
config.English: "Support native staking of IoTeX blockchain",
config.Chinese: "支持来自ioctl的本地质押",
config.Chinese: "支持来自 ioctl 的本地质押",
}
_stake2FlagEndpointUsages = map[config.Language]string{
config.English: "set endpoint for once",
config.Chinese: "一次设置所有端点",
}
_stake2FlagInsecureUsages = map[config.Language]string{
config.English: "insecure connection for once (default false)",
config.Chinese: "一次不安全的连接(默认为false)",
config.Chinese: "一次不安全的连接(默认为 false)",
}
_stake2FlagAutoStakeUsages = map[config.Language]string{
config.English: "auto-stake boost: the voting power will not decrease",
Expand All @@ -54,6 +54,9 @@ func init() {
Stake2Cmd.AddCommand(_stake2ReleaseCmd)
Stake2Cmd.AddCommand(_stake2RegisterCmd)
Stake2Cmd.AddCommand(_stake2ChangeCmd)
Stake2Cmd.AddCommand(_stake2EndorseCmd)
Stake2Cmd.AddCommand(_stake2UnEndorseCmd)
Stake2Cmd.AddCommand(_stake2ActivateCmd)
Stake2Cmd.PersistentFlags().StringVar(&config.ReadConfig.Endpoint, "endpoint", config.ReadConfig.Endpoint, config.TranslateInLang(_stake2FlagEndpointUsages, config.UILanguage))
Stake2Cmd.PersistentFlags().BoolVar(&config.Insecure, "insecure", config.Insecure, config.TranslateInLang(_stake2FlagInsecureUsages, config.UILanguage))
}
Expand Down
78 changes: 78 additions & 0 deletions ioctl/cmd/action/stake2activate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package action

import (
"strconv"

"github.com/spf13/cobra"

"github.com/iotexproject/iotex-core/action"
"github.com/iotexproject/iotex-core/ioctl/config"
"github.com/iotexproject/iotex-core/ioctl/output"
)

// Multi-language support
var (
_stake2ActivateCmdUses = map[config.Language]string{
config.English: "activate BUCKET_INDEX" +
" [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
config.Chinese: "activate 票索引" +
" [-s 签署人] [-n NONCE] [-l GAS 限制] [-p GAS 价格] [-P 密码] [-y]",
}

_stake2ActivateCmdShorts = map[config.Language]string{
config.English: "Activate candidate on IoTeX blockchain",
config.Chinese: "在 IoTeX 区块链上激活质押票的候选人",
}
)

var (
// _stake2ActivateCmd represents the stake2 transfer command
_stake2ActivateCmd = &cobra.Command{
Use: config.TranslateInLang(_stake2ActivateCmdUses, config.UILanguage),
Short: config.TranslateInLang(_stake2ActivateCmdShorts, config.UILanguage),
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
err := stake2Activate(args)
return output.PrintError(err)
},
}
)

func init() {
RegisterWriteCommand(_stake2ActivateCmd)
}

func stake2Activate(args []string) error {
bucketIndex, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return output.NewError(output.ConvertError, "failed to convert bucket index", nil)
}

sender, err := Signer()
if err != nil {
return output.NewError(output.AddressError, "failed to get signed address", err)
}

gasLimit := _gasLimitFlag.Value().(uint64)
if gasLimit == 0 {
gasLimit = action.CandidateActivateBaseIntrinsicGas
}

gasPriceRau, err := gasPriceInRau()
if err != nil {
return output.NewError(0, "failed to get gas price", err)
}
nonce, err := nonce(sender)
if err != nil {
return output.NewError(0, "failed to get nonce ", err)
}
s2t := action.NewCandidateActivate(nonce, gasLimit, gasPriceRau, bucketIndex)
return SendAction(
(&action.EnvelopeBuilder{}).
SetNonce(nonce).
SetGasPrice(gasPriceRau).
SetGasLimit(gasLimit).
SetAction(s2t).Build(),
sender)
}
112 changes: 112 additions & 0 deletions ioctl/cmd/action/stake2endorse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package action

import (
"strconv"

"github.com/spf13/cobra"

"github.com/iotexproject/iotex-core/action"
"github.com/iotexproject/iotex-core/ioctl/config"
"github.com/iotexproject/iotex-core/ioctl/output"
)

// Multi-language support
var (
_stake2EndorseCmdUses = map[config.Language]string{
config.English: "endorse BUCKET_INDEX" +
" [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
config.Chinese: "endorse 票索引" +
" [-s 签署人] [-n NONCE] [-l GAS 限制] [-p GAS 价格] [-P 密码] [-y]",
}
_stake2UnEndorseCmdUses = map[config.Language]string{
config.English: "unendorse BUCKET_INDEX" +
" [-s SIGNER] [-n NONCE] [-l GAS_LIMIT] [-p GAS_PRICE] [-P PASSWORD] [-y]",
config.Chinese: "unendorse 票索引" +
" [-s 签署人] [-n NONCE] [-l GAS 限制] [-p GAS 价格] [-P 密码] [-y]",
}

_stake2EndorseCmdShorts = map[config.Language]string{
config.English: "Endorse bucket's candidate on IoTeX blockchain",
config.Chinese: "在 IoTeX 区块链上背书候选人",
}
_stake2UnEndorseCmdShorts = map[config.Language]string{
config.English: "UnEndorse bucket's candidate on IoTeX blockchain",
config.Chinese: "在 IoTeX 区块链上撤销背书",
}
)

var (
// _stake2EndorseCmd represents the stake2 transfer command
_stake2EndorseCmd = &cobra.Command{
Use: config.TranslateInLang(_stake2EndorseCmdUses, config.UILanguage),
Short: config.TranslateInLang(_stake2EndorseCmdShorts, config.UILanguage),
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
err := stake2Endorse(args)
return output.PrintError(err)
},
}
_stake2UnEndorseCmd = &cobra.Command{
Use: config.TranslateInLang(_stake2UnEndorseCmdUses, config.UILanguage),
Short: config.TranslateInLang(_stake2UnEndorseCmdShorts, config.UILanguage),
Args: cobra.RangeArgs(1, 2),
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
err := stake2UnEndorse(args)
return output.PrintError(err)
},
}
)

func init() {
RegisterWriteCommand(_stake2EndorseCmd)
RegisterWriteCommand(_stake2UnEndorseCmd)
}

func stake2UnEndorse(args []string) error {
bucketIndex, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return output.NewError(output.ConvertError, "failed to convert bucket index", nil)
}

return doEndorsement(bucketIndex, false)
}

func stake2Endorse(args []string) error {
bucketIndex, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return output.NewError(output.ConvertError, "failed to convert bucket index", nil)
}

return doEndorsement(bucketIndex, true)
}

func doEndorsement(bucketIndex uint64, isEndorse bool) error {
sender, err := Signer()
if err != nil {
return output.NewError(output.AddressError, "failed to get signed address", err)
}

gasLimit := _gasLimitFlag.Value().(uint64)
if gasLimit == 0 {
gasLimit = action.CandidateEndorsementBaseIntrinsicGas
}

gasPriceRau, err := gasPriceInRau()
if err != nil {
return output.NewError(0, "failed to get gas price", err)
}
nonce, err := nonce(sender)
if err != nil {
return output.NewError(0, "failed to get nonce ", err)
}
s2t := action.NewCandidateEndorsement(nonce, gasLimit, gasPriceRau, bucketIndex, isEndorse)
return SendAction(
(&action.EnvelopeBuilder{}).
SetNonce(nonce).
SetGasPrice(gasPriceRau).
SetGasLimit(gasLimit).
SetAction(s2t).Build(),
sender)
}
2 changes: 1 addition & 1 deletion server/itx/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func newServer(cfg config.Config, testing bool) (*Server, error) {

// Start starts the server
func (s *Server) Start(ctx context.Context) error {
cctx, cancel := context.WithCancel(context.Background())
cctx, cancel := context.WithCancel(ctx)
s.subModuleCancel = cancel
for id, cs := range s.chainservices {
if err := cs.Start(cctx); err != nil {
Expand Down

0 comments on commit f664e2f

Please sign in to comment.