Fetch the repository succeeded.
package iwallet
import (
"fmt"
"strconv"
"gitee.com/aiou-official/go-aiou/sdk"
"gitee.com/aiou-official/go-aiou/rpc/pb"
"github.com/spf13/cobra"
)
var method string
var complete bool
var methodMap = map[string]func(string) (*rpcpb.BlockResponse, error){
"num": func(arg string) (*rpcpb.BlockResponse, error) {
num, err := strconv.ParseInt(arg, 10, 64)
if err != nil {
err = fmt.Errorf("invalid block number: %v", err)
return nil, err
}
return iwalletSDK.GetBlockByNum(num, complete)
},
"hash": func(arg string) (*rpcpb.BlockResponse, error) {
return iwalletSDK.GetBlockByHash(arg, complete)
},
}
// blockCmd represents the block command.
var blockCmd = &cobra.Command{
Use: "block blockNum|blockHash",
Short: "Print block info",
Long: `Print block info by block number or hash`,
Example: ` iwallet block 0
iwallet block 5dEgmyMURGfe7GxvTLajmaLXTkcqs5JwiJ2C2DE5VvVX -m hash`,
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errorWithHelp(cmd, "please enter the block number or hash")
}
_, ok := methodMap[method]
if !ok {
return errorWithHelp(cmd, "wrong method: %v", method)
}
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
blockInfo, err := methodMap[method](args[0])
if err != nil {
return err
}
fmt.Println(sdk.MarshalTextString(blockInfo))
return nil
},
}
func init() {
rootCmd.AddCommand(blockCmd)
blockCmd.Flags().StringVarP(&method, "method", "m", "num", `find by block num (set as "num") or hash (set as "hash")`)
blockCmd.Flags().BoolVarP(&complete, "complete", "c", false, "indicate whether to fetch all the transactions in the block or not")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。