Skip to content

Commit

Permalink
Merge pull request #1684 from nspcc-dev/candidate-registration-price
Browse files Browse the repository at this point in the history
native: make registering as a candidate cost more
  • Loading branch information
roman-khimov authored Jan 22, 2021
2 parents 0758333 + 476cbbe commit 6bc2512
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion cli/candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestRegisterCandidate(t *testing.T) {
"--wallet", validatorWallet,
"--from", validatorAddr,
"NEO:"+validatorPriv.Address()+":10",
"GAS:"+validatorPriv.Address()+":100")
"GAS:"+validatorPriv.Address()+":10000")
e.checkTxPersisted(t)

e.In.WriteString("one\r")
Expand Down
8 changes: 4 additions & 4 deletions cli/wallet/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ func newValidatorCommands() []cli.Command {
}

func handleRegister(ctx *cli.Context) error {
return handleCandidate(ctx, "registerCandidate")
return handleCandidate(ctx, "registerCandidate", 1001*100000000) // registering costs 1000 GAS
}

func handleUnregister(ctx *cli.Context) error {
return handleCandidate(ctx, "unregisterCandidate")
return handleCandidate(ctx, "unregisterCandidate", -1)
}

func handleCandidate(ctx *cli.Context, method string) error {
func handleCandidate(ctx *cli.Context, method string, sysGas int64) error {
wall, err := openWallet(ctx.String("wallet"))
if err != nil {
return cli.NewExitError(err, 1)
Expand Down Expand Up @@ -108,7 +108,7 @@ func handleCandidate(ctx *cli.Context, method string) error {
w := io.NewBufBinWriter()
emit.AppCall(w.BinWriter, neoContractHash, method, callflag.WriteStates, acc.PrivateKey().PublicKey().Bytes())
emit.Opcodes(w.BinWriter, opcode.ASSERT)
tx, err := c.CreateTxFromScript(w.Bytes(), acc, -1, int64(gas), transaction.Signer{
tx, err := c.CreateTxFromScript(w.Bytes(), acc, sysGas, int64(gas), transaction.Signer{
Account: acc.Contract.ScriptHash(),
Scopes: transaction.CalledByEntry,
})
Expand Down
4 changes: 2 additions & 2 deletions pkg/consensus/consensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func initServiceNextConsensus(t *testing.T, newAcc *wallet.Account, offset uint3
acc.Contract.ScriptHash().BytesBE(), newPriv.GetScriptHash().BytesBE(), int64(native.NEOTotalSupply), nil)
emit.Opcodes(w.BinWriter, opcode.ASSERT)
emit.AppCall(w.BinWriter, bc.UtilityTokenHash(), "transfer", callflag.All,
acc.Contract.ScriptHash().BytesBE(), newPriv.GetScriptHash().BytesBE(), int64(1_000_000_000), nil)
acc.Contract.ScriptHash().BytesBE(), newPriv.GetScriptHash().BytesBE(), int64(10000_000_000_000), nil)
emit.Opcodes(w.BinWriter, opcode.ASSERT)
require.NoError(t, w.Err)

Expand All @@ -78,7 +78,7 @@ func initServiceNextConsensus(t *testing.T, newAcc *wallet.Account, offset uint3
emit.AppCall(w.BinWriter, bc.GoverningTokenHash(), "registerCandidate", callflag.All, newPriv.PublicKey().Bytes())
require.NoError(t, w.Err)

tx = transaction.New(netmode.UnitTestNet, w.Bytes(), 20_000_000)
tx = transaction.New(netmode.UnitTestNet, w.Bytes(), 1001_00000000)
tx.ValidUntilBlock = bc.BlockHeight() + 1
tx.NetworkFee = 20_000_000
tx.Signers = []transaction.Signer{{Scopes: transaction.Global, Account: newPriv.GetScriptHash()}}
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/native/native_neo.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func newNEO() *NEO {

desc = newDescriptor("registerCandidate", smartcontract.BoolType,
manifest.NewParameter("pubkey", smartcontract.ByteArrayType))
md = newMethodAndPrice(n.registerCandidate, 5000000, callflag.WriteStates)
md = newMethodAndPrice(n.registerCandidate, 1000_00000000, callflag.WriteStates)
n.AddMethod(md, desc)

desc = newDescriptor("unregisterCandidate", smartcontract.BoolType,
Expand Down

0 comments on commit 6bc2512

Please sign in to comment.