Skip to content

Commit

Permalink
Merge pull request #1558 from nspcc-dev/nep17
Browse files Browse the repository at this point in the history
Replace NEP-5 with NEP-17
  • Loading branch information
roman-khimov authored Nov 24, 2020
2 parents 5f21178 + 31eca34 commit ad30f4d
Show file tree
Hide file tree
Showing 69 changed files with 637 additions and 633 deletions.
2 changes: 1 addition & 1 deletion cli/candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestRegisterCandidate(t *testing.T) {
defer e.Close(t)

e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "nep5", "multitransfer",
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",
"--rpc-endpoint", "http://"+e.RPC.Addr,
"--wallet", validatorWallet,
"--from", validatorAddr,
Expand Down
6 changes: 3 additions & 3 deletions cli/multisig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestSignMultisigTx(t *testing.T) {

// Transfer funds to the multisig.
e.In.WriteString("one\r")
e.Run(t, "neo-go", "wallet", "nep5", "multitransfer",
e.Run(t, "neo-go", "wallet", "nep17", "multitransfer",
"--rpc-endpoint", "http://"+e.RPC.Addr,
"--wallet", validatorWallet,
"--from", validatorAddr,
Expand All @@ -66,7 +66,7 @@ func TestSignMultisigTx(t *testing.T) {
txPath := path.Join(tmpDir, "multisigtx.json")
defer os.Remove(txPath)
e.In.WriteString("pass\r")
e.Run(t, "neo-go", "wallet", "nep5", "transfer",
e.Run(t, "neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://"+e.RPC.Addr,
"--wallet", wallet1Path, "--from", multisigAddr,
"--to", priv.Address(), "--token", "neo", "--amount", "1",
Expand All @@ -93,7 +93,7 @@ func TestSignMultisigTx(t *testing.T) {
e.Chain.GoverningTokenHash().StringLE(), "transfer",
"bytes:"+multisigHash.StringBE(),
"bytes:"+priv.GetScriptHash().StringBE(),
"int:1",
"int:1", "bytes:",
"--", strings.Join([]string{multisigHash.StringLE(), ":", "Global"}, ""))

e.In.WriteString("pass\r")
Expand Down
26 changes: 13 additions & 13 deletions cli/nep5_test.go → cli/nep17_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import (
"github.com/stretchr/testify/require"
)

func TestNEP5Balance(t *testing.T) {
func TestNEP17Balance(t *testing.T) {
e := newExecutor(t, true)
defer e.Close(t)
cmdbalance := []string{"neo-go", "wallet", "nep5", "balance"}
cmdbalance := []string{"neo-go", "wallet", "nep17", "balance"}
cmdbase := append(cmdbalance,
"--rpc-endpoint", "http://"+e.RPC.Addr,
"--wallet", validatorWallet,
Expand Down Expand Up @@ -99,15 +99,15 @@ func TestNEP5Balance(t *testing.T) {
return
}

func TestNEP5Transfer(t *testing.T) {
func TestNEP17Transfer(t *testing.T) {
w, err := wallet.NewWalletFromFile("testdata/testwallet.json")
require.NoError(t, err)
defer w.Close()

e := newExecutor(t, true)
defer e.Close(t)
args := []string{
"neo-go", "wallet", "nep5", "transfer",
"neo-go", "wallet", "nep17", "transfer",
"--rpc-endpoint", "http://" + e.RPC.Addr,
"--wallet", validatorWallet,
"--from", validatorAddr,
Expand All @@ -132,15 +132,15 @@ func TestNEP5Transfer(t *testing.T) {
require.Equal(t, big.NewInt(1), b)
}

func TestNEP5MultiTransfer(t *testing.T) {
func TestNEP17MultiTransfer(t *testing.T) {
privs, _ := generateKeys(t, 3)

e := newExecutor(t, true)
defer e.Close(t)
neoContractHash, err := e.Chain.GetNativeContractScriptHash("neo")
require.NoError(t, err)
args := []string{
"neo-go", "wallet", "nep5", "multitransfer",
"neo-go", "wallet", "nep17", "multitransfer",
"--rpc-endpoint", "http://" + e.RPC.Addr,
"--wallet", validatorWallet,
"--from", validatorAddr,
Expand All @@ -161,7 +161,7 @@ func TestNEP5MultiTransfer(t *testing.T) {
require.Equal(t, big.NewInt(13), b)
}

func TestNEP5ImportToken(t *testing.T) {
func TestNEP17ImportToken(t *testing.T) {
e := newExecutor(t, true)
defer e.Close(t)

Expand All @@ -174,11 +174,11 @@ func TestNEP5ImportToken(t *testing.T) {
gasContractHash, err := e.Chain.GetNativeContractScriptHash("gas")
require.NoError(t, err)
e.Run(t, "neo-go", "wallet", "init", "--wallet", walletPath)
e.Run(t, "neo-go", "wallet", "nep5", "import",
e.Run(t, "neo-go", "wallet", "nep17", "import",
"--rpc-endpoint", "http://"+e.RPC.Addr,
"--wallet", walletPath,
"--token", gasContractHash.StringLE())
e.Run(t, "neo-go", "wallet", "nep5", "import",
e.Run(t, "neo-go", "wallet", "nep17", "import",
"--rpc-endpoint", "http://"+e.RPC.Addr,
"--wallet", walletPath,
"--token", neoContractHash.StringLE())
Expand All @@ -192,12 +192,12 @@ func TestNEP5ImportToken(t *testing.T) {
e.checkNextLine(t, "^Address:\\s*"+address.Uint160ToString(gasContractHash))
}
t.Run("WithToken", func(t *testing.T) {
e.Run(t, "neo-go", "wallet", "nep5", "info",
e.Run(t, "neo-go", "wallet", "nep17", "info",
"--wallet", walletPath, "--token", gasContractHash.StringLE())
checkGASInfo(t)
})
t.Run("NoToken", func(t *testing.T) {
e.Run(t, "neo-go", "wallet", "nep5", "info",
e.Run(t, "neo-go", "wallet", "nep17", "info",
"--wallet", walletPath)
checkGASInfo(t)
_, err := e.Out.ReadString('\n')
Expand All @@ -210,9 +210,9 @@ func TestNEP5ImportToken(t *testing.T) {
})
t.Run("Remove", func(t *testing.T) {
e.In.WriteString("y\r")
e.Run(t, "neo-go", "wallet", "nep5", "remove",
e.Run(t, "neo-go", "wallet", "nep17", "remove",
"--wallet", walletPath, "--token", neoContractHash.StringLE())
e.Run(t, "neo-go", "wallet", "nep5", "info",
e.Run(t, "neo-go", "wallet", "nep17", "info",
"--wallet", walletPath)
checkGASInfo(t)
_, err := e.Out.ReadString('\n')
Expand Down
3 changes: 3 additions & 0 deletions cli/smartcontract/smart_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ func initSmartContract(ctx *cli.Context) error {
}

m := ProjectConfig{
Name: contractName,
SupportedStandards: []string{},
Events: []manifest.Event{
{
Expand Down Expand Up @@ -404,6 +405,7 @@ func contractCompile(ctx *cli.Context) error {
if err != nil {
return err
}
o.Name = conf.Name
o.ContractEvents = conf.Events
o.ContractSupportedStandards = conf.SupportedStandards
}
Expand Down Expand Up @@ -631,6 +633,7 @@ func testInvokeScript(ctx *cli.Context) error {

// ProjectConfig contains project metadata.
type ProjectConfig struct {
Name string
SupportedStandards []string
Events []manifest.Event
}
Expand Down
3 changes: 2 additions & 1 deletion cli/smartcontract/smart_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func RuntimeNotify(args []interface{}) {
manifest, err := ioutil.ReadFile(contractName + "/" + files[1].Name())
require.NoError(t, err)
require.Equal(t,
`supportedstandards: []
`name: testContract
supportedstandards: []
events:
- name: Hello world!
parameters:
Expand Down
3 changes: 3 additions & 0 deletions cli/testdata/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ package testdata
func Verify() bool {
return true
}

func OnPayment(from []byte, amount int, data interface{}) {
}
2 changes: 1 addition & 1 deletion cli/testdata/verify.manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"abi":{"hash":"0x8dff9f223e4622961f410c015dd37052a59892bb","methods":[{"name":"verify","offset":0,"parameters":[],"returntype":"Boolean"}],"events":[]},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"safemethods":[],"extra":null}
{"name":"verify","abi":{"hash":"0xbf214a7551e50d6fbe0bef05271719325d9fc1ef","methods":[{"name":"verify","offset":0,"parameters":[],"returntype":"Boolean"},{"name":"onPayment","offset":5,"parameters":[{"name":"from","type":"ByteArray"},{"name":"amount","type":"Integer"},{"name":"data","type":"Any"}],"returntype":"Void"}],"events":[]},"groups":[],"permissions":[{"contract":"*","methods":"*"}],"supportedstandards":[],"trusts":[],"safemethods":[],"extra":null}
Binary file modified cli/testdata/verify.nef
Binary file not shown.
48 changes: 24 additions & 24 deletions cli/wallet/nep5.go → cli/wallet/nep17.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
}
)

func newNEP5Commands() []cli.Command {
func newNEP17Commands() []cli.Command {
balanceFlags := []cli.Flag{
walletPathFlag,
tokenFlag,
Expand Down Expand Up @@ -69,21 +69,21 @@ func newNEP5Commands() []cli.Command {
Name: "balance",
Usage: "get address balance",
UsageText: "balance --wallet <path> --rpc-endpoint <node> [--timeout <time>] [--address <address>] [--token <hash-or-name>]",
Action: getNEP5Balance,
Action: getNEP17Balance,
Flags: balanceFlags,
},
{
Name: "import",
Usage: "import NEP5 token to a wallet",
Usage: "import NEP17 token to a wallet",
UsageText: "import --wallet <path> --rpc-endpoint <node> --timeout <time> --token <hash>",
Action: importNEP5Token,
Action: importNEP17Token,
Flags: importFlags,
},
{
Name: "info",
Usage: "print imported NEP5 token info",
Usage: "print imported NEP17 token info",
UsageText: "print --wallet <path> [--token <hash-or-name>]",
Action: printNEP5Info,
Action: printNEP17Info,
Flags: []cli.Flag{
walletPathFlag,
cli.StringFlag{
Expand All @@ -94,9 +94,9 @@ func newNEP5Commands() []cli.Command {
},
{
Name: "remove",
Usage: "remove NEP5 token from the wallet",
Usage: "remove NEP17 token from the wallet",
UsageText: "remove --wallet <path> --token <hash-or-name>",
Action: removeNEP5Token,
Action: removeNEP17Token,
Flags: []cli.Flag{
walletPathFlag,
cli.StringFlag{
Expand All @@ -108,23 +108,23 @@ func newNEP5Commands() []cli.Command {
},
{
Name: "transfer",
Usage: "transfer NEP5 tokens",
Usage: "transfer NEP17 tokens",
UsageText: "transfer --wallet <path> --rpc-endpoint <node> --timeout <time> --from <addr> --to <addr> --token <hash> --amount string",
Action: transferNEP5,
Action: transferNEP17,
Flags: transferFlags,
},
{
Name: "multitransfer",
Usage: "transfer NEP5 tokens to multiple recipients",
Usage: "transfer NEP17 tokens to multiple recipients",
UsageText: `multitransfer --wallet <path> --rpc-endpoint <node> --timeout <time> --from <addr>` +
` <token1>:<addr1>:<amount1> [<token2>:<addr2>:<amount2> [...]]`,
Action: multiTransferNEP5,
Action: multiTransferNEP17,
Flags: multiTransferFlags,
},
}
}

func getNEP5Balance(ctx *cli.Context) error {
func getNEP17Balance(ctx *cli.Context) error {
var accounts []*wallet.Account

wall, err := openWallet(ctx.String("wallet"))
Expand Down Expand Up @@ -170,7 +170,7 @@ func getNEP5Balance(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(fmt.Errorf("invalid account address: %w", err), 1)
}
balances, err := c.GetNEP5Balances(addrHash)
balances, err := c.GetNEP17Balances(addrHash)
if err != nil {
return cli.NewExitError(err, 1)
}
Expand All @@ -186,7 +186,7 @@ func getNEP5Balance(ctx *cli.Context) error {
asset := balances.Balances[i].Asset
token, err := getMatchingToken(ctx, wall, asset.StringLE())
if err != nil {
token, err = c.NEP5TokenInfo(asset)
token, err = c.NEP17TokenInfo(asset)
}
if err == nil {
if name != "" && !(token.Name == name || token.Symbol == name || token.Address() == name || token.Hash.StringLE() == name) {
Expand Down Expand Up @@ -215,12 +215,12 @@ func getMatchingToken(ctx *cli.Context, w *wallet.Wallet, name string) (*wallet.
}

func getMatchingTokenRPC(ctx *cli.Context, c *client.Client, addr util.Uint160, name string) (*wallet.Token, error) {
bs, err := c.GetNEP5Balances(addr)
bs, err := c.GetNEP17Balances(addr)
if err != nil {
return nil, err
}
get := func(i int) *wallet.Token {
t, _ := c.NEP5TokenInfo(bs.Balances[i].Asset)
t, _ := c.NEP17TokenInfo(bs.Balances[i].Asset)
return t
}
return getMatchingTokenAux(ctx, get, len(bs.Balances), name)
Expand All @@ -247,7 +247,7 @@ func getMatchingTokenAux(ctx *cli.Context, get func(i int) *wallet.Token, n int,
return token, nil
}

func importNEP5Token(ctx *cli.Context) error {
func importNEP17Token(ctx *cli.Context) error {
wall, err := openWallet(ctx.String("wallet"))
if err != nil {
return cli.NewExitError(err, 1)
Expand All @@ -274,7 +274,7 @@ func importNEP5Token(ctx *cli.Context) error {
return cli.NewExitError(err, 1)
}

tok, err := c.NEP5TokenInfo(tokenHash)
tok, err := c.NEP17TokenInfo(tokenHash)
if err != nil {
return cli.NewExitError(fmt.Errorf("can't receive token info: %w", err), 1)
}
Expand All @@ -296,7 +296,7 @@ func printTokenInfo(ctx *cli.Context, tok *wallet.Token) {
fmt.Fprintf(w, "Address: %s\n", tok.Address())
}

func printNEP5Info(ctx *cli.Context) error {
func printNEP17Info(ctx *cli.Context) error {
wall, err := openWallet(ctx.String("wallet"))
if err != nil {
return cli.NewExitError(err, 1)
Expand All @@ -321,7 +321,7 @@ func printNEP5Info(ctx *cli.Context) error {
return nil
}

func removeNEP5Token(ctx *cli.Context) error {
func removeNEP17Token(ctx *cli.Context) error {
wall, err := openWallet(ctx.String("wallet"))
if err != nil {
return cli.NewExitError(err, 1)
Expand All @@ -345,7 +345,7 @@ func removeNEP5Token(ctx *cli.Context) error {
return nil
}

func multiTransferNEP5(ctx *cli.Context) error {
func multiTransferNEP17(ctx *cli.Context) error {
wall, err := openWallet(ctx.String("wallet"))
if err != nil {
return cli.NewExitError(err, 1)
Expand Down Expand Up @@ -412,7 +412,7 @@ func multiTransferNEP5(ctx *cli.Context) error {
return signAndSendTransfer(ctx, c, acc, recipients)
}

func transferNEP5(ctx *cli.Context) error {
func transferNEP17(ctx *cli.Context) error {
wall, err := openWallet(ctx.String("wallet"))
if err != nil {
return cli.NewExitError(err, 1)
Expand Down Expand Up @@ -464,7 +464,7 @@ func transferNEP5(ctx *cli.Context) error {
func signAndSendTransfer(ctx *cli.Context, c *client.Client, acc *wallet.Account, recipients []client.TransferTarget) error {
gas := flags.Fixed8FromContext(ctx, "gas")

tx, err := c.CreateNEP5MultiTransferTx(acc, int64(gas), recipients...)
tx, err := c.CreateNEP17MultiTransferTx(acc, int64(gas), recipients...)
if err != nil {
return cli.NewExitError(err, 1)
}
Expand Down
8 changes: 4 additions & 4 deletions cli/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ func NewCommands() []cli.Command {
Subcommands: newMultisigCommands(),
},
{
Name: "nep5",
Usage: "work with NEP5 contracts",
Subcommands: newNEP5Commands(),
Name: "nep17",
Usage: "work with NEP17 contracts",
Subcommands: newNEP17Commands(),
},
{
Name: "candidate",
Expand Down Expand Up @@ -237,7 +237,7 @@ func claimGas(ctx *cli.Context) error {
if err != nil {
return cli.NewExitError(err, 1)
}
hash, err := c.TransferNEP5(acc, scriptHash, neoContractHash, 0, 0)
hash, err := c.TransferNEP17(acc, scriptHash, neoContractHash, 0, 0)
if err != nil {
return cli.NewExitError(err, 1)
}
Expand Down
Loading

0 comments on commit ad30f4d

Please sign in to comment.