-
Notifications
You must be signed in to change notification settings - Fork 324
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
[ioctl] build xrc20 transfer from command line into new ioctl #3444
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3444 +/- ##
==========================================
- Coverage 75.43% 74.87% -0.56%
==========================================
Files 247 267 +20
Lines 22845 23753 +908
==========================================
+ Hits 17233 17786 +553
- Misses 4685 5042 +357
+ Partials 927 925 -2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
ioctl/newcmd/action/action.go
Outdated
"github.com/iotexproject/iotex-core/ioctl" | ||
"github.com/iotexproject/iotex-core/ioctl/flag" |
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.
iotex-core should be a single group. put line17~18 to line36
ioctl/client.go
Outdated
@@ -154,6 +156,11 @@ func (c *client) SelectTranslation(trls map[config.Language]string) (string, con | |||
return trl, config.English | |||
} | |||
|
|||
func (c *client) SelectTranslationText(trls map[config.Language]string) string { |
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.
no need
Use: config.TranslateInLang(_xrc20TransferFromCmdUses, config.UILanguage), | ||
Short: config.TranslateInLang(_xrc20TransferFromCmdShorts, config.UILanguage), |
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.
use client.SelectTranslation()
return errors.Wrap(err, "cannot generate bytecode from given command") | ||
} | ||
err = Execute(client, cmd, contract.String(), big.NewInt(0), bytecode) | ||
return output.PrintError(err) |
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.
don's use output
.
ioctl/newcmd/action/action.go
Outdated
if addressOrAlias == "" { | ||
addressOrAlias, err = config.GetContextAddressOrAlias() | ||
if err != nil { | ||
return | ||
} | ||
} |
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.
these are done in line 254,
ioctl/newcmd/action/xrc20.go
Outdated
"math/big" | ||
"strconv" | ||
|
||
"github.com/iotexproject/iotex-core/ioctl" |
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.
put iotex-core
together
ioctl/newcmd/action/xrc20.go
Outdated
"github.com/pkg/errors" | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/iotexproject/iotex-address/address" |
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.
these are another single group
ioctl/newcmd/action/xrc20.go
Outdated
|
||
"github.com/iotexproject/iotex-address/address" | ||
|
||
"github.com/iotexproject/iotex-core/ioctl/cmd/alias" |
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.
don't use iotex-core/ioctl/cmd/
, use iotex-core/ioctl/newcmd/
"math/big" | ||
|
||
"github.com/iotexproject/iotex-core/ioctl" | ||
"github.com/iotexproject/iotex-core/ioctl/cmd/alias" |
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.
don't use iotex-core/ioctl/cmd/
, use iotex-core/ioctl/newcmd/
ioctl/newcmd/action/xrc20const.go
Outdated
} | ||
]` | ||
|
||
var _xrc20ABI abi.ABI |
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.
put global variable into client.
if err != nil { | ||
return errors.Wrap(err, "failed to parse amount") | ||
} | ||
bytecode, err := _xrc20ABI.Pack("transferFrom", owner, recipient, amount) |
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.
put line59 into client and use like client.PackABI
Pls create _test.go and add unit test. |
ioctl/newcmd/action/action.go
Outdated
URL string `json:"url"` | ||
} | ||
|
||
func (m *sendMessage) String() string { |
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.
PackABI is used in some commands. client warps the common operations. command can use client's method to do own business.
ioctl/client_abi.go
Outdated
) | ||
|
||
// PackABI pack abi with abi content, pack name and arguments | ||
func PackABI(content string, name string, args ...interface{}) ([]byte, error) { |
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.
not global. should be client's method
ioctl/client_abi.go
Outdated
// ABI JSON content | ||
|
||
var ( | ||
XRC20ABI = `[{"constant":false,"inputs":[{"name":"spender","type":"address"},{"name":"value","type":"uint256"}],"name":"approve","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"from","type":"address"},{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transferFrom","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"who","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"to","type":"address"},{"name":"value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"name":"allowance","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":true,"name":"owner","type":"address"},{"indexed":true,"name":"spender","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Approval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]` |
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.
not global. should be client's member.
if err != nil { | ||
return errors.Wrap(err, "failed to parse amount") | ||
} | ||
bytecode, err := ioctl.PackABI(ioctl.XRC20ABI, "transferFrom", owner, recipient, amount) |
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.
client.packABI("transferFrom", owner, recipient, amount)
@saitofun fix ci Fail |
@saitofun I fixed, pls check it. Thx |
already fix it |
after #3472 merged, this pr continue. because the same file |
ioctl/client.go
Outdated
xrc20ABI, err := abi.JSON(strings.NewReader(_xrc20ABI)) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "cannot get abi JSON data") | ||
} |
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 may put it into init
, and panic if any error
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.
fixed
ioctl/client.go
Outdated
@@ -397,6 +426,10 @@ func (c *client) WriteHdWalletConfigFile(mnemonic string, password string) error | |||
return nil | |||
} | |||
|
|||
func (c *client) PackABI(name string, args ...interface{}) ([]byte, error) { | |||
return c.xrc20ABI.Pack(name, args...) |
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.
xrc20abi is more like a const, instead of a parameter of client
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.
xrc20ABI.Pack(name, args...)
is used in other xrc20 commands: xrc20_allowance、 xrc20_approve ....
so make this function.
It seems that xrc20abi has nothing to do with client. If so, I will put it into package of xrc20.
ioctl/newcmd/action/xrc20.go
Outdated
|
||
client.SetEndpointWithFlag(cmd.PersistentFlags().StringVar) | ||
client.SetInsecureWithFlag(cmd.PersistentFlags().BoolVar) | ||
client.SetXrc20ContractAddrWithFlag(cmd.PersistentFlags().StringVarP, cmd.MarkFlagRequired) |
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.
xrc20 contract address is not a client feature.
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.
ok,
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
@huof6829 could you help fix the ci failure? |
Description
[ioctl] build xrc20 transfer from command line into new ioctl
Fixes #3339
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Checklist: