transaction: drop Enrollment and State types
They're completely replaced now by the NEO native contract voting system.
This commit is contained in:
parent
b83e84ca08
commit
e6f5cffff6
18 changed files with 6 additions and 415 deletions
|
@ -24,7 +24,6 @@ ProtocolConfiguration:
|
||||||
- seed9.ngd.network:10333
|
- seed9.ngd.network:10333
|
||||||
- seed10.ngd.network:10333
|
- seed10.ngd.network:10333
|
||||||
SystemFee:
|
SystemFee:
|
||||||
EnrollmentTransaction: 1000
|
|
||||||
IssueTransaction: 500
|
IssueTransaction: 500
|
||||||
RegisterTransaction: 10000
|
RegisterTransaction: 10000
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
|
|
|
@ -15,7 +15,6 @@ ProtocolConfiguration:
|
||||||
- 172.200.0.3:20335
|
- 172.200.0.3:20335
|
||||||
- 172.200.0.4:20336
|
- 172.200.0.4:20336
|
||||||
SystemFee:
|
SystemFee:
|
||||||
EnrollmentTransaction: 1000
|
|
||||||
IssueTransaction: 500
|
IssueTransaction: 500
|
||||||
RegisterTransaction: 10000
|
RegisterTransaction: 10000
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
|
|
|
@ -15,7 +15,6 @@ ProtocolConfiguration:
|
||||||
- 172.200.0.3:20335
|
- 172.200.0.3:20335
|
||||||
- 172.200.0.4:20336
|
- 172.200.0.4:20336
|
||||||
SystemFee:
|
SystemFee:
|
||||||
EnrollmentTransaction: 1000
|
|
||||||
IssueTransaction: 500
|
IssueTransaction: 500
|
||||||
RegisterTransaction: 10000
|
RegisterTransaction: 10000
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
|
|
|
@ -9,7 +9,6 @@ ProtocolConfiguration:
|
||||||
SeedList:
|
SeedList:
|
||||||
- 172.200.0.1:20333
|
- 172.200.0.1:20333
|
||||||
SystemFee:
|
SystemFee:
|
||||||
EnrollmentTransaction: 1000
|
|
||||||
IssueTransaction: 500
|
IssueTransaction: 500
|
||||||
RegisterTransaction: 10000
|
RegisterTransaction: 10000
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
|
|
|
@ -15,7 +15,6 @@ ProtocolConfiguration:
|
||||||
- 172.200.0.3:20335
|
- 172.200.0.3:20335
|
||||||
- 172.200.0.4:20336
|
- 172.200.0.4:20336
|
||||||
SystemFee:
|
SystemFee:
|
||||||
EnrollmentTransaction: 1000
|
|
||||||
IssueTransaction: 500
|
IssueTransaction: 500
|
||||||
RegisterTransaction: 10000
|
RegisterTransaction: 10000
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
|
|
|
@ -15,7 +15,6 @@ ProtocolConfiguration:
|
||||||
- 172.200.0.3:20335
|
- 172.200.0.3:20335
|
||||||
- 172.200.0.4:20336
|
- 172.200.0.4:20336
|
||||||
SystemFee:
|
SystemFee:
|
||||||
EnrollmentTransaction: 1000
|
|
||||||
IssueTransaction: 500
|
IssueTransaction: 500
|
||||||
RegisterTransaction: 10000
|
RegisterTransaction: 10000
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
|
|
|
@ -24,7 +24,6 @@ ProtocolConfiguration:
|
||||||
- seed9.ngd.network:20333
|
- seed9.ngd.network:20333
|
||||||
- seed10.ngd.network:20333
|
- seed10.ngd.network:20333
|
||||||
SystemFee:
|
SystemFee:
|
||||||
EnrollmentTransaction: 10
|
|
||||||
IssueTransaction: 5
|
IssueTransaction: 5
|
||||||
RegisterTransaction: 100
|
RegisterTransaction: 100
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
|
|
|
@ -14,7 +14,6 @@ ProtocolConfiguration:
|
||||||
- 127.0.0.1:20335
|
- 127.0.0.1:20335
|
||||||
- 127.0.0.1:20336
|
- 127.0.0.1:20336
|
||||||
SystemFee:
|
SystemFee:
|
||||||
EnrollmentTransaction: 1000
|
|
||||||
IssueTransaction: 500
|
IssueTransaction: 500
|
||||||
RegisterTransaction: 10000
|
RegisterTransaction: 10000
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
|
|
|
@ -47,9 +47,8 @@ type (
|
||||||
|
|
||||||
// SystemFee fees related to system.
|
// SystemFee fees related to system.
|
||||||
SystemFee struct {
|
SystemFee struct {
|
||||||
EnrollmentTransaction int64 `yaml:"EnrollmentTransaction"`
|
IssueTransaction int64 `yaml:"IssueTransaction"`
|
||||||
IssueTransaction int64 `yaml:"IssueTransaction"`
|
RegisterTransaction int64 `yaml:"RegisterTransaction"`
|
||||||
RegisterTransaction int64 `yaml:"RegisterTransaction"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetMode describes the mode the blockchain will operate on.
|
// 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.
|
// TryGetValue returns the system fee base on transaction type.
|
||||||
func (s SystemFee) TryGetValue(txType transaction.TXType) util.Fixed8 {
|
func (s SystemFee) TryGetValue(txType transaction.TXType) util.Fixed8 {
|
||||||
switch txType {
|
switch txType {
|
||||||
case transaction.EnrollmentType:
|
|
||||||
return util.Fixed8FromInt64(s.EnrollmentTransaction)
|
|
||||||
case transaction.IssueType:
|
case transaction.IssueType:
|
||||||
return util.Fixed8FromInt64(s.IssueTransaction)
|
return util.Fixed8FromInt64(s.IssueTransaction)
|
||||||
case transaction.RegisterType:
|
case transaction.RegisterType:
|
||||||
|
|
|
@ -831,23 +831,6 @@ func processOutputs(tx *transaction.Transaction, dao *dao.Cached) error {
|
||||||
return nil
|
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.
|
// persist flushes current in-memory Store contents to the persistent storage.
|
||||||
func (bc *Blockchain) persist() error {
|
func (bc *Blockchain) persist() error {
|
||||||
var (
|
var (
|
||||||
|
@ -1268,63 +1251,6 @@ func (bc *Blockchain) verifyTx(t *transaction.Transaction, block *block.Block) e
|
||||||
if inv.Gas.FractionalValue() != 0 {
|
if inv.Gas.FractionalValue() != 0 {
|
||||||
return errors.New("invocation gas can only be integer")
|
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)
|
return bc.verifyTxWitnesses(t, block)
|
||||||
|
@ -1662,9 +1588,6 @@ func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([
|
||||||
for i := range refs {
|
for i := range refs {
|
||||||
hashes[refs[i].Out.ScriptHash] = true
|
hashes[refs[i].Out.ScriptHash] = true
|
||||||
}
|
}
|
||||||
case transaction.EnrollmentType:
|
|
||||||
etx := t.Data.(*transaction.EnrollmentTX)
|
|
||||||
hashes[etx.PublicKey.GetScriptHash()] = true
|
|
||||||
case transaction.IssueType:
|
case transaction.IssueType:
|
||||||
for _, res := range refsAndOutsToResults(references, t.Outputs) {
|
for _, res := range refsAndOutsToResults(references, t.Outputs) {
|
||||||
if res.Amount < 0 {
|
if res.Amount < 0 {
|
||||||
|
@ -1678,31 +1601,6 @@ func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([
|
||||||
case transaction.RegisterType:
|
case transaction.RegisterType:
|
||||||
reg := t.Data.(*transaction.RegisterTX)
|
reg := t.Data.(*transaction.RegisterTX)
|
||||||
hashes[reg.Owner.GetScriptHash()] = true
|
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
|
// convert hashes to []util.Uint160
|
||||||
hashesResult := make([]util.Uint160, 0, len(hashes))
|
hashesResult := make([]util.Uint160, 0, len(hashes))
|
||||||
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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))
|
|
||||||
}
|
|
||||||
*/
|
|
|
@ -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)
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
}
|
|
|
@ -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))
|
|
||||||
}
|
|
||||||
*/
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
"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/encoding/address"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
|
@ -164,12 +163,6 @@ func (t *Transaction) decodeData(r *io.BinReader) {
|
||||||
case IssueType:
|
case IssueType:
|
||||||
t.Data = &IssueTX{}
|
t.Data = &IssueTX{}
|
||||||
t.Data.(*IssueTX).DecodeBinary(r)
|
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:
|
default:
|
||||||
r.Err = fmt.Errorf("invalid TX type %x", t.Type)
|
r.Err = fmt.Errorf("invalid TX type %x", t.Type)
|
||||||
}
|
}
|
||||||
|
@ -281,12 +274,10 @@ type transactionJSON struct {
|
||||||
Outputs []Output `json:"vout"`
|
Outputs []Output `json:"vout"`
|
||||||
Scripts []Witness `json:"scripts"`
|
Scripts []Witness `json:"scripts"`
|
||||||
|
|
||||||
Claims []Input `json:"claims,omitempty"`
|
Claims []Input `json:"claims,omitempty"`
|
||||||
PublicKey *keys.PublicKey `json:"pubkey,omitempty"`
|
Script string `json:"script,omitempty"`
|
||||||
Script string `json:"script,omitempty"`
|
Gas util.Fixed8 `json:"gas,omitempty"`
|
||||||
Gas util.Fixed8 `json:"gas,omitempty"`
|
Asset *registeredAsset `json:"asset,omitempty"`
|
||||||
Asset *registeredAsset `json:"asset,omitempty"`
|
|
||||||
Descriptors []*StateDescriptor `json:"descriptors,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON implements json.Marshaler interface.
|
// MarshalJSON implements json.Marshaler interface.
|
||||||
|
@ -307,8 +298,6 @@ func (t *Transaction) MarshalJSON() ([]byte, error) {
|
||||||
switch t.Type {
|
switch t.Type {
|
||||||
case ClaimType:
|
case ClaimType:
|
||||||
tx.Claims = t.Data.(*ClaimTX).Claims
|
tx.Claims = t.Data.(*ClaimTX).Claims
|
||||||
case EnrollmentType:
|
|
||||||
tx.PublicKey = &t.Data.(*EnrollmentTX).PublicKey
|
|
||||||
case InvocationType:
|
case InvocationType:
|
||||||
tx.Script = hex.EncodeToString(t.Data.(*InvocationTX).Script)
|
tx.Script = hex.EncodeToString(t.Data.(*InvocationTX).Script)
|
||||||
tx.Gas = t.Data.(*InvocationTX).Gas
|
tx.Gas = t.Data.(*InvocationTX).Gas
|
||||||
|
@ -322,8 +311,6 @@ func (t *Transaction) MarshalJSON() ([]byte, error) {
|
||||||
Owner: transaction.Owner,
|
Owner: transaction.Owner,
|
||||||
Admin: address.Uint160ToString(transaction.Admin),
|
Admin: address.Uint160ToString(transaction.Admin),
|
||||||
}
|
}
|
||||||
case StateType:
|
|
||||||
tx.Descriptors = t.Data.(*StateTX).Descriptors
|
|
||||||
}
|
}
|
||||||
return json.Marshal(tx)
|
return json.Marshal(tx)
|
||||||
}
|
}
|
||||||
|
@ -354,10 +341,6 @@ func (t *Transaction) UnmarshalJSON(data []byte) error {
|
||||||
t.Data = &ClaimTX{
|
t.Data = &ClaimTX{
|
||||||
Claims: tx.Claims,
|
Claims: tx.Claims,
|
||||||
}
|
}
|
||||||
case EnrollmentType:
|
|
||||||
t.Data = &EnrollmentTX{
|
|
||||||
PublicKey: *tx.PublicKey,
|
|
||||||
}
|
|
||||||
case InvocationType:
|
case InvocationType:
|
||||||
bytes, err := hex.DecodeString(tx.Script)
|
bytes, err := hex.DecodeString(tx.Script)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -381,10 +364,6 @@ func (t *Transaction) UnmarshalJSON(data []byte) error {
|
||||||
Owner: tx.Asset.Owner,
|
Owner: tx.Asset.Owner,
|
||||||
Admin: admin,
|
Admin: admin,
|
||||||
}
|
}
|
||||||
case StateType:
|
|
||||||
t.Data = &StateTX{
|
|
||||||
Descriptors: tx.Descriptors,
|
|
||||||
}
|
|
||||||
case ContractType:
|
case ContractType:
|
||||||
t.Data = &ContractTX{}
|
t.Data = &ContractTX{}
|
||||||
case IssueType:
|
case IssueType:
|
||||||
|
|
|
@ -154,32 +154,6 @@ func TestMarshalUnmarshalJSONClaimTX(t *testing.T) {
|
||||||
testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction))
|
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) {
|
func TestMarshalUnmarshalJSONInvocationTX(t *testing.T) {
|
||||||
tx := &Transaction{
|
tx := &Transaction{
|
||||||
Type: InvocationType,
|
Type: InvocationType,
|
||||||
|
@ -236,33 +210,3 @@ func TestMarshalUnmarshalJSONRegisterTX(t *testing.T) {
|
||||||
|
|
||||||
testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction))
|
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))
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,10 +14,8 @@ const (
|
||||||
MinerType TXType = 0x00
|
MinerType TXType = 0x00
|
||||||
IssueType TXType = 0x01
|
IssueType TXType = 0x01
|
||||||
ClaimType TXType = 0x02
|
ClaimType TXType = 0x02
|
||||||
EnrollmentType TXType = 0x20
|
|
||||||
RegisterType TXType = 0x40
|
RegisterType TXType = 0x40
|
||||||
ContractType TXType = 0x80
|
ContractType TXType = 0x80
|
||||||
StateType TXType = 0x90
|
|
||||||
InvocationType TXType = 0xd1
|
InvocationType TXType = 0xd1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,14 +28,10 @@ func (t TXType) String() string {
|
||||||
return "IssueTransaction"
|
return "IssueTransaction"
|
||||||
case ClaimType:
|
case ClaimType:
|
||||||
return "ClaimTransaction"
|
return "ClaimTransaction"
|
||||||
case EnrollmentType:
|
|
||||||
return "EnrollmentTransaction"
|
|
||||||
case RegisterType:
|
case RegisterType:
|
||||||
return "RegisterTransaction"
|
return "RegisterTransaction"
|
||||||
case ContractType:
|
case ContractType:
|
||||||
return "ContractTransaction"
|
return "ContractTransaction"
|
||||||
case StateType:
|
|
||||||
return "StateTransaction"
|
|
||||||
case InvocationType:
|
case InvocationType:
|
||||||
return "InvocationTransaction"
|
return "InvocationTransaction"
|
||||||
default:
|
default:
|
||||||
|
@ -70,14 +64,10 @@ func TXTypeFromString(jsonString string) (TXType, error) {
|
||||||
return IssueType, nil
|
return IssueType, nil
|
||||||
case "ClaimTransaction":
|
case "ClaimTransaction":
|
||||||
return ClaimType, nil
|
return ClaimType, nil
|
||||||
case "EnrollmentTransaction":
|
|
||||||
return EnrollmentType, nil
|
|
||||||
case "RegisterTransaction":
|
case "RegisterTransaction":
|
||||||
return RegisterType, nil
|
return RegisterType, nil
|
||||||
case "ContractTransaction":
|
case "ContractTransaction":
|
||||||
return ContractType, nil
|
return ContractType, nil
|
||||||
case "StateTransaction":
|
|
||||||
return StateType, nil
|
|
||||||
case "InvocationTransaction":
|
case "InvocationTransaction":
|
||||||
return InvocationType, nil
|
return InvocationType, nil
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue