transaction: drop Enrollment and State types

They're completely replaced now by the NEO native contract voting system.
This commit is contained in:
Roman Khimov 2020-04-26 20:16:39 +03:00
parent b83e84ca08
commit e6f5cffff6
18 changed files with 6 additions and 415 deletions

View file

@ -24,7 +24,6 @@ ProtocolConfiguration:
- seed9.ngd.network:10333
- seed10.ngd.network:10333
SystemFee:
EnrollmentTransaction: 1000
IssueTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true

View file

@ -15,7 +15,6 @@ ProtocolConfiguration:
- 172.200.0.3:20335
- 172.200.0.4:20336
SystemFee:
EnrollmentTransaction: 1000
IssueTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true

View file

@ -15,7 +15,6 @@ ProtocolConfiguration:
- 172.200.0.3:20335
- 172.200.0.4:20336
SystemFee:
EnrollmentTransaction: 1000
IssueTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true

View file

@ -9,7 +9,6 @@ ProtocolConfiguration:
SeedList:
- 172.200.0.1:20333
SystemFee:
EnrollmentTransaction: 1000
IssueTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true

View file

@ -15,7 +15,6 @@ ProtocolConfiguration:
- 172.200.0.3:20335
- 172.200.0.4:20336
SystemFee:
EnrollmentTransaction: 1000
IssueTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true

View file

@ -15,7 +15,6 @@ ProtocolConfiguration:
- 172.200.0.3:20335
- 172.200.0.4:20336
SystemFee:
EnrollmentTransaction: 1000
IssueTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true

View file

@ -24,7 +24,6 @@ ProtocolConfiguration:
- seed9.ngd.network:20333
- seed10.ngd.network:20333
SystemFee:
EnrollmentTransaction: 10
IssueTransaction: 5
RegisterTransaction: 100
VerifyBlocks: true

View file

@ -14,7 +14,6 @@ ProtocolConfiguration:
- 127.0.0.1:20335
- 127.0.0.1:20336
SystemFee:
EnrollmentTransaction: 1000
IssueTransaction: 500
RegisterTransaction: 10000
VerifyBlocks: true

View file

@ -47,9 +47,8 @@ type (
// SystemFee fees related to system.
SystemFee struct {
EnrollmentTransaction int64 `yaml:"EnrollmentTransaction"`
IssueTransaction int64 `yaml:"IssueTransaction"`
RegisterTransaction int64 `yaml:"RegisterTransaction"`
IssueTransaction int64 `yaml:"IssueTransaction"`
RegisterTransaction int64 `yaml:"RegisterTransaction"`
}
// NetMode describes the mode the blockchain will operate on.
@ -75,8 +74,6 @@ func (n NetMode) String() string {
// TryGetValue returns the system fee base on transaction type.
func (s SystemFee) TryGetValue(txType transaction.TXType) util.Fixed8 {
switch txType {
case transaction.EnrollmentType:
return util.Fixed8FromInt64(s.EnrollmentTransaction)
case transaction.IssueType:
return util.Fixed8FromInt64(s.IssueTransaction)
case transaction.RegisterType:

View file

@ -831,23 +831,6 @@ func processOutputs(tx *transaction.Transaction, dao *dao.Cached) error {
return nil
}
func (bc *Blockchain) processAccountStateDescriptor(descriptor *transaction.StateDescriptor, t *transaction.Transaction, dao *dao.Cached) error {
hash, err := util.Uint160DecodeBytesBE(descriptor.Key)
if err != nil {
return err
}
if descriptor.Field == "Votes" {
votes := keys.PublicKeys{}
if err := votes.DecodeBytes(descriptor.Value); err != nil {
return err
}
ic := bc.newInteropContext(trigger.Application, dao, nil, t)
return bc.contracts.NEO.VoteInternal(ic, hash, votes)
}
return nil
}
// persist flushes current in-memory Store contents to the persistent storage.
func (bc *Blockchain) persist() error {
var (
@ -1268,63 +1251,6 @@ func (bc *Blockchain) verifyTx(t *transaction.Transaction, block *block.Block) e
if inv.Gas.FractionalValue() != 0 {
return errors.New("invocation gas can only be integer")
}
case transaction.StateType:
stx := t.Data.(*transaction.StateTX)
for _, desc := range stx.Descriptors {
switch desc.Type {
case transaction.Account:
if desc.Field != "Votes" {
return errors.New("bad field in account descriptor")
}
votes := keys.PublicKeys{}
err := votes.DecodeBytes(desc.Value)
if err != nil {
return err
}
if len(votes) > native.MaxValidatorsVoted {
return errors.New("voting candidate limit exceeded")
}
hash, err := util.Uint160DecodeBytesBE(desc.Key)
if err != nil {
return err
}
account, err := bc.dao.GetAccountStateOrNew(hash)
if err != nil {
return err
}
if account.IsFrozen {
return errors.New("account is frozen")
}
if votes.Len() > 0 {
balance := account.GetBalanceValues()[GoverningTokenID()]
if balance == 0 {
return errors.New("no governing tokens available to vote")
}
validators, err := bc.GetEnrollments()
if err != nil {
return err
}
for _, k := range votes {
var isRegistered bool
for i := range validators {
if k.Equal(validators[i].Key) {
isRegistered = true
break
}
}
if !isRegistered {
return errors.New("vote for unregistered validator")
}
}
}
case transaction.Validator:
if desc.Field != "Registered" {
return errors.New("bad field in validator descriptor")
}
default:
return errors.New("bad descriptor type")
}
}
}
return bc.verifyTxWitnesses(t, block)
@ -1662,9 +1588,6 @@ func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([
for i := range refs {
hashes[refs[i].Out.ScriptHash] = true
}
case transaction.EnrollmentType:
etx := t.Data.(*transaction.EnrollmentTX)
hashes[etx.PublicKey.GetScriptHash()] = true
case transaction.IssueType:
for _, res := range refsAndOutsToResults(references, t.Outputs) {
if res.Amount < 0 {
@ -1678,31 +1601,6 @@ func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([
case transaction.RegisterType:
reg := t.Data.(*transaction.RegisterTX)
hashes[reg.Owner.GetScriptHash()] = true
case transaction.StateType:
stx := t.Data.(*transaction.StateTX)
for _, desc := range stx.Descriptors {
switch desc.Type {
case transaction.Account:
if desc.Field != "Votes" {
return nil, errors.New("bad account state descriptor")
}
hash, err := util.Uint160DecodeBytesBE(desc.Key)
if err != nil {
return nil, err
}
hashes[hash] = true
case transaction.Validator:
if desc.Field != "Registered" {
return nil, errors.New("bad validator state descriptor")
}
key := &keys.PublicKey{}
err := key.DecodeBytes(desc.Key)
if err != nil {
return nil, err
}
hashes[key.GetScriptHash()] = true
}
}
}
// convert hashes to []util.Uint160
hashesResult := make([]util.Uint160, 0, len(hashes))

View file

@ -1,43 +0,0 @@
package transaction
import (
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/io"
)
// EnrollmentTX transaction represents an enrollment form, which indicates
// that the sponsor of the transaction would like to sign up as a validator.
// The way to sign up is: To construct an EnrollmentTransaction type of transaction,
// and send a deposit to the address of the PublicKey.
// The way to cancel the registration is: Spend the deposit on the address of the PublicKey.
type EnrollmentTX struct {
// PublicKey of the validator.
PublicKey keys.PublicKey
}
// NewEnrollmentTX creates Transaction of EnrollmentType type.
func NewEnrollmentTX(enrollment *EnrollmentTX) *Transaction {
return &Transaction{
Type: EnrollmentType,
Version: 0,
Nonce: rand.Uint32(),
Data: enrollment,
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
Trimmed: false,
}
}
// DecodeBinary implements Serializable interface.
func (tx *EnrollmentTX) DecodeBinary(r *io.BinReader) {
tx.PublicKey.DecodeBinary(r)
}
// EncodeBinary implements Serializable interface.
func (tx *EnrollmentTX) EncodeBinary(w *io.BinWriter) {
tx.PublicKey.EncodeBinary(w)
}

View file

@ -1,17 +0,0 @@
package transaction
//TODO NEO3.0: Update bynary
/*
func TestEncodeDecodeEnrollment(t *testing.T) {
rawtx := "200002ff8ac54687f36bbc31a91b730cc385da8af0b581f2d59d82b5cfef824fd271f60001d3d3b7028d61fea3b7803fda3d7f0a1f7262d38e5e1c8987b0313e0a94574151000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c60005441d11600000050ac4949596f5b62fef7be4d1c3e494e6048ed4a01414079d78189d591097b17657a62240c93595e8233dc81157ea2cd477813f09a11fd72845e6bd97c5a3dda125985ea3d5feca387e9933649a9a671a69ab3f6301df6232102ff8ac54687f36bbc31a91b730cc385da8af0b581f2d59d82b5cfef824fd271f6ac"
tx := decodeTransaction(rawtx, t)
assert.Equal(t, "988832f693785dcbcb8d5a0e9d5d22002adcbfb1eb6bbeebf8c494fff580e147", tx.Hash().StringLE())
assert.Equal(t, EnrollmentType, tx.Type)
assert.IsType(t, tx.Data, &EnrollmentTX{})
assert.Equal(t, 0, int(tx.Version))
data, err := testserdes.EncodeBinary(tx)
assert.Equal(t, nil, err)
assert.Equal(t, rawtx, hex.EncodeToString(data))
}
*/

View file

@ -1,37 +0,0 @@
package transaction
import (
"math/rand"
"github.com/nspcc-dev/neo-go/pkg/io"
)
// StateTX represents a state transaction.
type StateTX struct {
Descriptors []*StateDescriptor
}
// NewStateTX creates Transaction of StateType type.
func NewStateTX(state *StateTX) *Transaction {
return &Transaction{
Type: StateType,
Version: 0,
Nonce: rand.Uint32(),
Data: state,
Attributes: []Attribute{},
Inputs: []Input{},
Outputs: []Output{},
Scripts: []Witness{},
Trimmed: false,
}
}
// DecodeBinary implements Serializable interface.
func (tx *StateTX) DecodeBinary(r *io.BinReader) {
r.ReadArray(&tx.Descriptors)
}
// EncodeBinary implements Serializable interface.
func (tx *StateTX) EncodeBinary(w *io.BinWriter) {
w.WriteArray(tx.Descriptors)
}

View file

@ -1,81 +0,0 @@
package transaction
import (
"encoding/hex"
"encoding/json"
"github.com/nspcc-dev/neo-go/pkg/io"
)
// DescStateType represents the type of StateDescriptor.
type DescStateType uint8
// Valid DescStateType constants.
const (
Account DescStateType = 0x40
Validator DescStateType = 0x48
)
// StateDescriptor ..
type StateDescriptor struct {
Type DescStateType
Key []byte
Value []byte
Field string
}
// DecodeBinary implements Serializable interface.
func (s *StateDescriptor) DecodeBinary(r *io.BinReader) {
s.Type = DescStateType(r.ReadB())
s.Key = r.ReadVarBytes()
s.Field = r.ReadString()
s.Value = r.ReadVarBytes()
}
// EncodeBinary implements Serializable interface.
func (s *StateDescriptor) EncodeBinary(w *io.BinWriter) {
w.WriteB(byte(s.Type))
w.WriteVarBytes(s.Key)
w.WriteString(s.Field)
w.WriteVarBytes(s.Value)
}
// stateDescriptor is a wrapper for StateDescriptor
type stateDescriptor struct {
Type DescStateType `json:"type"`
Key string `json:"key"`
Value string `json:"value"`
Field string `json:"field"`
}
// MarshalJSON implements json.Marshaler interface.
func (s *StateDescriptor) MarshalJSON() ([]byte, error) {
return json.Marshal(&stateDescriptor{
Type: s.Type,
Key: hex.EncodeToString(s.Key),
Value: hex.EncodeToString(s.Value),
Field: s.Field,
})
}
// UnmarshalJSON implements json.Unmarshaler interface.
func (s *StateDescriptor) UnmarshalJSON(data []byte) error {
t := new(stateDescriptor)
if err := json.Unmarshal(data, t); err != nil {
return err
}
key, err := hex.DecodeString(t.Key)
if err != nil {
return err
}
value, err := hex.DecodeString(t.Value)
if err != nil {
return err
}
s.Key = key
s.Value = value
s.Field = t.Field
s.Type = t.Type
return nil
}

View file

@ -1,31 +0,0 @@
package transaction
//TODO NEO3.0: Update binary
/*
func TestEncodeDecodeState(t *testing.T) {
// transaction taken from testnet 8abf5ebdb9a8223b12109513647f45bd3c0a6cf1a6346d56684cff71ba308724
rawtx := "900001482103c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c10a5265676973746572656401010001cb4184f0a96e72656c1fbdd4f75cca567519e909fd43cefcec13d6c6abcb92a1000001e72d286979ee6cb1b7e65dfddfb2e384100b8d148e7758de42e4168b71792c6000b8fb050109000071f9cf7f0ec74ec0b0f28a92b12e1081574c0af00141408780d7b3c0aadc5398153df5e2f1cf159db21b8b0f34d3994d865433f79fafac41683783c48aef510b67660e3157b701b9ca4dd9946a385d578fba7dd26f4849232103c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c1ac"
tx := decodeTransaction(rawtx, t)
assert.Equal(t, StateType, tx.Type)
assert.IsType(t, tx.Data, &StateTX{})
assert.Equal(t, "8abf5ebdb9a8223b12109513647f45bd3c0a6cf1a6346d56684cff71ba308724", tx.Hash().StringLE())
assert.Equal(t, 1, len(tx.Inputs))
input := tx.Inputs[0]
assert.Equal(t, "a192cbabc6d613ecfcce43fd09e9197556ca5cf7d4bd1f6c65726ea9f08441cb", input.PrevHash.StringLE())
assert.Equal(t, uint16(0), input.PrevIndex)
s := tx.Data.(*StateTX)
assert.Equal(t, 1, len(s.Descriptors))
descriptor := s.Descriptors[0]
assert.Equal(t, "03c089d7122b840a4935234e82e26ae5efd0c2acb627239dc9f207311337b6f2c1", hex.EncodeToString(descriptor.Key))
assert.Equal(t, "Registered", descriptor.Field)
assert.Equal(t, []byte{0x01}, descriptor.Value)
assert.Equal(t, Validator, descriptor.Type)
// Encode
data, err := testserdes.EncodeBinary(tx)
assert.NoError(t, err)
assert.Equal(t, rawtx, hex.EncodeToString(data))
}
*/

View file

@ -7,7 +7,6 @@ import (
"fmt"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
"github.com/nspcc-dev/neo-go/pkg/io"
"github.com/nspcc-dev/neo-go/pkg/util"
@ -164,12 +163,6 @@ func (t *Transaction) decodeData(r *io.BinReader) {
case IssueType:
t.Data = &IssueTX{}
t.Data.(*IssueTX).DecodeBinary(r)
case EnrollmentType:
t.Data = &EnrollmentTX{}
t.Data.(*EnrollmentTX).DecodeBinary(r)
case StateType:
t.Data = &StateTX{}
t.Data.(*StateTX).DecodeBinary(r)
default:
r.Err = fmt.Errorf("invalid TX type %x", t.Type)
}
@ -281,12 +274,10 @@ type transactionJSON struct {
Outputs []Output `json:"vout"`
Scripts []Witness `json:"scripts"`
Claims []Input `json:"claims,omitempty"`
PublicKey *keys.PublicKey `json:"pubkey,omitempty"`
Script string `json:"script,omitempty"`
Gas util.Fixed8 `json:"gas,omitempty"`
Asset *registeredAsset `json:"asset,omitempty"`
Descriptors []*StateDescriptor `json:"descriptors,omitempty"`
Claims []Input `json:"claims,omitempty"`
Script string `json:"script,omitempty"`
Gas util.Fixed8 `json:"gas,omitempty"`
Asset *registeredAsset `json:"asset,omitempty"`
}
// MarshalJSON implements json.Marshaler interface.
@ -307,8 +298,6 @@ func (t *Transaction) MarshalJSON() ([]byte, error) {
switch t.Type {
case ClaimType:
tx.Claims = t.Data.(*ClaimTX).Claims
case EnrollmentType:
tx.PublicKey = &t.Data.(*EnrollmentTX).PublicKey
case InvocationType:
tx.Script = hex.EncodeToString(t.Data.(*InvocationTX).Script)
tx.Gas = t.Data.(*InvocationTX).Gas
@ -322,8 +311,6 @@ func (t *Transaction) MarshalJSON() ([]byte, error) {
Owner: transaction.Owner,
Admin: address.Uint160ToString(transaction.Admin),
}
case StateType:
tx.Descriptors = t.Data.(*StateTX).Descriptors
}
return json.Marshal(tx)
}
@ -354,10 +341,6 @@ func (t *Transaction) UnmarshalJSON(data []byte) error {
t.Data = &ClaimTX{
Claims: tx.Claims,
}
case EnrollmentType:
t.Data = &EnrollmentTX{
PublicKey: *tx.PublicKey,
}
case InvocationType:
bytes, err := hex.DecodeString(tx.Script)
if err != nil {
@ -381,10 +364,6 @@ func (t *Transaction) UnmarshalJSON(data []byte) error {
Owner: tx.Asset.Owner,
Admin: admin,
}
case StateType:
t.Data = &StateTX{
Descriptors: tx.Descriptors,
}
case ContractType:
t.Data = &ContractTX{}
case IssueType:

View file

@ -154,32 +154,6 @@ func TestMarshalUnmarshalJSONClaimTX(t *testing.T) {
testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction))
}
func TestMarshalUnmarshalJSONEnrollmentTX(t *testing.T) {
str := "03b209fd4f53a7170ea4444e0cb0a6bb6a53c2bd016926989cf85f9b0fba17a70c"
pubKey, err := keys.NewPublicKeyFromString(str)
require.NoError(t, err)
tx := &Transaction{
Type: EnrollmentType,
Version: 5,
Data: &EnrollmentTX{PublicKey: *pubKey},
Attributes: []Attribute{},
Inputs: []Input{{
PrevHash: util.Uint256{5, 6, 7, 8},
PrevIndex: uint16(12),
}},
Outputs: []Output{{
AssetID: util.Uint256{1, 2, 3},
Amount: util.Fixed8FromInt64(1),
ScriptHash: util.Uint160{1, 2, 3},
Position: 0,
}},
Scripts: []Witness{},
Trimmed: false,
}
testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction))
}
func TestMarshalUnmarshalJSONInvocationTX(t *testing.T) {
tx := &Transaction{
Type: InvocationType,
@ -236,33 +210,3 @@ func TestMarshalUnmarshalJSONRegisterTX(t *testing.T) {
testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction))
}
func TestMarshalUnmarshalJSONStateTX(t *testing.T) {
tx := &Transaction{
Type: StateType,
Version: 5,
Data: &StateTX{
Descriptors: []*StateDescriptor{&StateDescriptor{
Type: Validator,
Key: []byte{1, 2, 3},
Value: []byte{4, 5, 6},
Field: "Field",
}},
},
Attributes: []Attribute{},
Inputs: []Input{{
PrevHash: util.Uint256{5, 6, 7, 8},
PrevIndex: uint16(12),
}},
Outputs: []Output{{
AssetID: util.Uint256{1, 2, 3},
Amount: util.Fixed8FromInt64(1),
ScriptHash: util.Uint160{1, 2, 3},
Position: 0,
}},
Scripts: []Witness{},
Trimmed: false,
}
testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction))
}

View file

@ -14,10 +14,8 @@ const (
MinerType TXType = 0x00
IssueType TXType = 0x01
ClaimType TXType = 0x02
EnrollmentType TXType = 0x20
RegisterType TXType = 0x40
ContractType TXType = 0x80
StateType TXType = 0x90
InvocationType TXType = 0xd1
)
@ -30,14 +28,10 @@ func (t TXType) String() string {
return "IssueTransaction"
case ClaimType:
return "ClaimTransaction"
case EnrollmentType:
return "EnrollmentTransaction"
case RegisterType:
return "RegisterTransaction"
case ContractType:
return "ContractTransaction"
case StateType:
return "StateTransaction"
case InvocationType:
return "InvocationTransaction"
default:
@ -70,14 +64,10 @@ func TXTypeFromString(jsonString string) (TXType, error) {
return IssueType, nil
case "ClaimTransaction":
return ClaimType, nil
case "EnrollmentTransaction":
return EnrollmentType, nil
case "RegisterTransaction":
return RegisterType, nil
case "ContractTransaction":
return ContractType, nil
case "StateTransaction":
return StateType, nil
case "InvocationTransaction":
return InvocationType, nil
default: