mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 13:41:37 +00:00
transaction: drop Register transaction type
And everything associated like SystemFee configuration.
This commit is contained in:
parent
169c5ae775
commit
0a09a20900
22 changed files with 5 additions and 335 deletions
|
@ -11,7 +11,6 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/cli/flags"
|
"github.com/nspcc-dev/neo-go/cli/flags"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
"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/rpc/client"
|
"github.com/nspcc-dev/neo-go/pkg/rpc/client"
|
||||||
|
@ -510,18 +509,6 @@ func openWallet(path string) (*wallet.Wallet, error) {
|
||||||
return wallet.NewWalletFromFile(path)
|
return wallet.NewWalletFromFile(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAssetID(s string) (util.Uint256, error) {
|
|
||||||
s = strings.ToLower(s)
|
|
||||||
switch {
|
|
||||||
case s == "neo":
|
|
||||||
return core.GoverningTokenID(), nil
|
|
||||||
case s == "gas":
|
|
||||||
return core.UtilityTokenID(), nil
|
|
||||||
default:
|
|
||||||
return util.Uint256DecodeStringLE(s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newAccountFromWIF(wif string) (*wallet.Account, error) {
|
func newAccountFromWIF(wif string) (*wallet.Account, error) {
|
||||||
// note: NEP2 strings always have length of 58 even though
|
// note: NEP2 strings always have length of 58 even though
|
||||||
// base58 strings can have different lengths even if slice lengths are equal
|
// base58 strings can have different lengths even if slice lengths are equal
|
||||||
|
|
|
@ -18,8 +18,6 @@ ProtocolConfiguration:
|
||||||
- seed3.neo.org:10333
|
- seed3.neo.org:10333
|
||||||
- seed4.neo.org:10333
|
- seed4.neo.org:10333
|
||||||
- seed5.neo.org:10333
|
- seed5.neo.org:10333
|
||||||
SystemFee:
|
|
||||||
RegisterTransaction: 10000
|
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
VerifyTransactions: false
|
VerifyTransactions: false
|
||||||
FreeGasLimit: 10.0
|
FreeGasLimit: 10.0
|
||||||
|
|
|
@ -14,8 +14,6 @@ ProtocolConfiguration:
|
||||||
- 172.200.0.2:20334
|
- 172.200.0.2:20334
|
||||||
- 172.200.0.3:20335
|
- 172.200.0.3:20335
|
||||||
- 172.200.0.4:20336
|
- 172.200.0.4:20336
|
||||||
SystemFee:
|
|
||||||
RegisterTransaction: 10000
|
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
VerifyTransactions: true
|
VerifyTransactions: true
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,6 @@ ProtocolConfiguration:
|
||||||
- 172.200.0.2:20334
|
- 172.200.0.2:20334
|
||||||
- 172.200.0.3:20335
|
- 172.200.0.3:20335
|
||||||
- 172.200.0.4:20336
|
- 172.200.0.4:20336
|
||||||
SystemFee:
|
|
||||||
RegisterTransaction: 10000
|
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
VerifyTransactions: true
|
VerifyTransactions: true
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,6 @@ ProtocolConfiguration:
|
||||||
- 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2
|
- 02b3622bf4017bdfe317c58aed5f4c753f206b7db896046fa7d774bbc4bf7f8dc2
|
||||||
SeedList:
|
SeedList:
|
||||||
- 172.200.0.1:20333
|
- 172.200.0.1:20333
|
||||||
SystemFee:
|
|
||||||
RegisterTransaction: 10000
|
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
VerifyTransactions: true
|
VerifyTransactions: true
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,6 @@ ProtocolConfiguration:
|
||||||
- 172.200.0.2:20334
|
- 172.200.0.2:20334
|
||||||
- 172.200.0.3:20335
|
- 172.200.0.3:20335
|
||||||
- 172.200.0.4:20336
|
- 172.200.0.4:20336
|
||||||
SystemFee:
|
|
||||||
RegisterTransaction: 10000
|
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
VerifyTransactions: true
|
VerifyTransactions: true
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,6 @@ ProtocolConfiguration:
|
||||||
- 172.200.0.2:20334
|
- 172.200.0.2:20334
|
||||||
- 172.200.0.3:20335
|
- 172.200.0.3:20335
|
||||||
- 172.200.0.4:20336
|
- 172.200.0.4:20336
|
||||||
SystemFee:
|
|
||||||
RegisterTransaction: 10000
|
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
VerifyTransactions: true
|
VerifyTransactions: true
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,6 @@ ProtocolConfiguration:
|
||||||
- 127.0.0.1:20334
|
- 127.0.0.1:20334
|
||||||
- 127.0.0.1:20335
|
- 127.0.0.1:20335
|
||||||
- 127.0.0.1:20336
|
- 127.0.0.1:20336
|
||||||
SystemFee:
|
|
||||||
EnrollmentTransaction: 1000
|
|
||||||
RegisterTransaction: 10000
|
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
VerifyTransactions: true
|
VerifyTransactions: true
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@ ProtocolConfiguration:
|
||||||
- seed3t.neo.org:20333
|
- seed3t.neo.org:20333
|
||||||
- seed4t.neo.org:20333
|
- seed4t.neo.org:20333
|
||||||
- seed5t.neo.org:20333
|
- seed5t.neo.org:20333
|
||||||
SystemFee:
|
|
||||||
RegisterTransaction: 100
|
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
VerifyTransactions: false
|
VerifyTransactions: false
|
||||||
FreeGasLimit: 10.0
|
FreeGasLimit: 10.0
|
||||||
|
|
|
@ -13,8 +13,6 @@ ProtocolConfiguration:
|
||||||
- 127.0.0.1:20334
|
- 127.0.0.1:20334
|
||||||
- 127.0.0.1:20335
|
- 127.0.0.1:20335
|
||||||
- 127.0.0.1:20336
|
- 127.0.0.1:20336
|
||||||
SystemFee:
|
|
||||||
RegisterTransaction: 10000
|
|
||||||
VerifyBlocks: true
|
VerifyBlocks: true
|
||||||
VerifyTransactions: true
|
VerifyTransactions: true
|
||||||
|
|
||||||
|
|
|
@ -59,8 +59,6 @@ ProtocolConfiguration:
|
||||||
- 127.0.0.1:20334
|
- 127.0.0.1:20334
|
||||||
- 127.0.0.1:20335
|
- 127.0.0.1:20335
|
||||||
- 127.0.0.1:20336
|
- 127.0.0.1:20336
|
||||||
SystemFee:
|
|
||||||
RegisterTransaction: 10000
|
|
||||||
|
|
||||||
ApplicationConfiguration:
|
ApplicationConfiguration:
|
||||||
DataDirectoryPath: "./chains/privnet"
|
DataDirectoryPath: "./chains/privnet"
|
||||||
|
|
|
@ -40,9 +40,6 @@ func Load(path string, netMode NetMode) (Config, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
config := Config{
|
config := Config{
|
||||||
ProtocolConfiguration: ProtocolConfiguration{
|
|
||||||
SystemFee: SystemFee{},
|
|
||||||
},
|
|
||||||
ApplicationConfiguration: ApplicationConfiguration{
|
ApplicationConfiguration: ApplicationConfiguration{
|
||||||
PingInterval: 30,
|
PingInterval: 30,
|
||||||
PingTimeout: 90,
|
PingTimeout: 90,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,18 +37,12 @@ type (
|
||||||
SecondsPerBlock int `yaml:"SecondsPerBlock"`
|
SecondsPerBlock int `yaml:"SecondsPerBlock"`
|
||||||
SeedList []string `yaml:"SeedList"`
|
SeedList []string `yaml:"SeedList"`
|
||||||
StandbyValidators []string `yaml:"StandbyValidators"`
|
StandbyValidators []string `yaml:"StandbyValidators"`
|
||||||
SystemFee SystemFee `yaml:"SystemFee"`
|
|
||||||
// Whether to verify received blocks.
|
// Whether to verify received blocks.
|
||||||
VerifyBlocks bool `yaml:"VerifyBlocks"`
|
VerifyBlocks bool `yaml:"VerifyBlocks"`
|
||||||
// Whether to verify transactions in received blocks.
|
// Whether to verify transactions in received blocks.
|
||||||
VerifyTransactions bool `yaml:"VerifyTransactions"`
|
VerifyTransactions bool `yaml:"VerifyTransactions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SystemFee fees related to system.
|
|
||||||
SystemFee struct {
|
|
||||||
RegisterTransaction int64 `yaml:"RegisterTransaction"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NetMode describes the mode the blockchain will operate on.
|
// NetMode describes the mode the blockchain will operate on.
|
||||||
NetMode uint32
|
NetMode uint32
|
||||||
)
|
)
|
||||||
|
@ -69,13 +62,3 @@ func (n NetMode) String() string {
|
||||||
return "net unknown"
|
return "net unknown"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TryGetValue returns the system fee base on transaction type.
|
|
||||||
func (s SystemFee) TryGetValue(txType transaction.TXType) util.Fixed8 {
|
|
||||||
switch txType {
|
|
||||||
case transaction.RegisterType:
|
|
||||||
return util.Fixed8FromInt64(s.RegisterTransaction)
|
|
||||||
default:
|
|
||||||
return util.Fixed8FromInt64(0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -33,13 +33,6 @@ const (
|
||||||
headerBatchCount = 2000
|
headerBatchCount = 2000
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
||||||
// This one comes from C# code and it's different from the constant used
|
|
||||||
// when creating an asset with Neo.Asset.Create interop call. It looks
|
|
||||||
// like 2000000 is coming from the decrementInterval, but C# code doesn't
|
|
||||||
// contain any relationship between the two, so we should follow this
|
|
||||||
// behavior.
|
|
||||||
registeredAssetLifetime = 2 * 2000000
|
|
||||||
|
|
||||||
defaultMemPoolSize = 50000
|
defaultMemPoolSize = 50000
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -629,20 +622,6 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
||||||
|
|
||||||
// Process the underlying type of the TX.
|
// Process the underlying type of the TX.
|
||||||
switch t := tx.Data.(type) {
|
switch t := tx.Data.(type) {
|
||||||
case *transaction.RegisterTX:
|
|
||||||
err := cache.PutAssetState(&state.Asset{
|
|
||||||
ID: tx.Hash(),
|
|
||||||
AssetType: t.AssetType,
|
|
||||||
Name: t.Name,
|
|
||||||
Amount: t.Amount,
|
|
||||||
Precision: t.Precision,
|
|
||||||
Owner: t.Owner,
|
|
||||||
Admin: t.Admin,
|
|
||||||
Expiration: bc.BlockHeight() + registeredAssetLifetime,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
case *transaction.InvocationTX:
|
case *transaction.InvocationTX:
|
||||||
systemInterop := bc.newInteropContext(trigger.Application, cache, block, tx)
|
systemInterop := bc.newInteropContext(trigger.Application, cache, block, tx)
|
||||||
v := SpawnVM(systemInterop)
|
v := SpawnVM(systemInterop)
|
||||||
|
@ -1420,9 +1399,6 @@ func (bc *Blockchain) verifyResults(t *transaction.Transaction, results []*trans
|
||||||
if len(resultsDestroy) > 1 {
|
if len(resultsDestroy) > 1 {
|
||||||
return errors.New("tx has more than 1 destroy output")
|
return errors.New("tx has more than 1 destroy output")
|
||||||
}
|
}
|
||||||
if len(resultsDestroy) == 1 && resultsDestroy[0].AssetID != UtilityTokenID() {
|
|
||||||
return errors.New("tx destroys non-utility token")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(resultsIssue) > 0 {
|
if len(resultsIssue) > 0 {
|
||||||
return errors.New("non issue/miner/claim tx issues tokens")
|
return errors.New("non issue/miner/claim tx issues tokens")
|
||||||
|
@ -1515,11 +1491,6 @@ func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([
|
||||||
for _, c := range t.Cosigners {
|
for _, c := range t.Cosigners {
|
||||||
hashes[c.Account] = true
|
hashes[c.Account] = true
|
||||||
}
|
}
|
||||||
switch t.Type {
|
|
||||||
case transaction.RegisterType:
|
|
||||||
reg := t.Data.(*transaction.RegisterTX)
|
|
||||||
hashes[reg.Owner.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))
|
||||||
for h := range hashes {
|
for h := range hashes {
|
||||||
|
|
|
@ -1,82 +0,0 @@
|
||||||
package transaction
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
// RegisterTX represents a register transaction.
|
|
||||||
// NOTE: This is deprecated.
|
|
||||||
type RegisterTX struct {
|
|
||||||
// The type of the asset being registered.
|
|
||||||
AssetType AssetType
|
|
||||||
|
|
||||||
// Name of the asset being registered.
|
|
||||||
Name string
|
|
||||||
|
|
||||||
// Amount registered.
|
|
||||||
// Unlimited mode -0.00000001.
|
|
||||||
Amount util.Fixed8
|
|
||||||
|
|
||||||
// Decimals.
|
|
||||||
Precision uint8
|
|
||||||
|
|
||||||
// Public key of the owner.
|
|
||||||
Owner keys.PublicKey
|
|
||||||
|
|
||||||
Admin util.Uint160
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRegisterTX creates Transaction of RegisterType type.
|
|
||||||
func NewRegisterTX(register *RegisterTX) *Transaction {
|
|
||||||
return &Transaction{
|
|
||||||
Type: RegisterType,
|
|
||||||
Version: 0,
|
|
||||||
Nonce: rand.Uint32(),
|
|
||||||
Data: register,
|
|
||||||
Attributes: []Attribute{},
|
|
||||||
Cosigners: []Cosigner{},
|
|
||||||
Inputs: []Input{},
|
|
||||||
Outputs: []Output{},
|
|
||||||
Scripts: []Witness{},
|
|
||||||
Trimmed: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeBinary implements Serializable interface.
|
|
||||||
func (tx *RegisterTX) DecodeBinary(br *io.BinReader) {
|
|
||||||
tx.AssetType = AssetType(br.ReadB())
|
|
||||||
|
|
||||||
tx.Name = br.ReadString()
|
|
||||||
|
|
||||||
tx.Amount.DecodeBinary(br)
|
|
||||||
tx.Precision = uint8(br.ReadB())
|
|
||||||
|
|
||||||
tx.Owner.DecodeBinary(br)
|
|
||||||
|
|
||||||
tx.Admin.DecodeBinary(br)
|
|
||||||
}
|
|
||||||
|
|
||||||
// EncodeBinary implements Serializable interface.
|
|
||||||
func (tx *RegisterTX) EncodeBinary(bw *io.BinWriter) {
|
|
||||||
bw.WriteB(byte(tx.AssetType))
|
|
||||||
bw.WriteString(tx.Name)
|
|
||||||
tx.Amount.EncodeBinary(bw)
|
|
||||||
bw.WriteB(byte(tx.Precision))
|
|
||||||
bw.WriteBytes(tx.Owner.Bytes())
|
|
||||||
tx.Admin.EncodeBinary(bw)
|
|
||||||
}
|
|
||||||
|
|
||||||
// registeredAsset is a wrapper for RegisterTransaction
|
|
||||||
type registeredAsset struct {
|
|
||||||
AssetType AssetType `json:"type,omitempty"`
|
|
||||||
Name json.RawMessage `json:"name,omitempty"`
|
|
||||||
Amount util.Fixed8 `json:"amount,omitempty"`
|
|
||||||
Precision uint8 `json:"precision,omitempty"`
|
|
||||||
Owner keys.PublicKey `json:"owner,omitempty"`
|
|
||||||
Admin string `json:"admin,omitempty"`
|
|
||||||
}
|
|
|
@ -1,46 +0,0 @@
|
||||||
package transaction
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestRegisterTX(t *testing.T) {
|
|
||||||
someuint160, _ := util.Uint160DecodeStringBE("4d3b96ae1bcc5a585e075e3b81920210dec16302")
|
|
||||||
registerTx := &RegisterTX{
|
|
||||||
AssetType: UtilityToken,
|
|
||||||
Name: "this is some token I created",
|
|
||||||
Amount: util.Fixed8FromInt64(1000000),
|
|
||||||
Precision: 8,
|
|
||||||
Admin: someuint160,
|
|
||||||
}
|
|
||||||
tx := NewRegisterTX(registerTx)
|
|
||||||
_ = tx.Hash()
|
|
||||||
|
|
||||||
testserdes.EncodeDecodeBinary(t, tx, new(Transaction))
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO NEO3.0: update binary
|
|
||||||
/*
|
|
||||||
func TestDecodeRegisterTXFromRawString(t *testing.T) {
|
|
||||||
rawTX := "400000455b7b226c616e67223a227a682d434e222c226e616d65223a22e5b08fe89a81e882a1227d2c7b226c616e67223a22656e222c226e616d65223a22416e745368617265227d5d0000c16ff28623000000da1745e9b549bd0bfa1a569971c77eba30cd5a4b00000000"
|
|
||||||
b, err := hex.DecodeString(rawTX)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
tx := &Transaction{}
|
|
||||||
assert.NoError(t, testserdes.DecodeBinary(b, tx))
|
|
||||||
assert.Equal(t, RegisterType, tx.Type)
|
|
||||||
txData := tx.Data.(*RegisterTX)
|
|
||||||
assert.Equal(t, GoverningToken, txData.AssetType)
|
|
||||||
assert.Equal(t, "[{\"lang\":\"zh-CN\",\"name\":\"小蚁股\"},{\"lang\":\"en\",\"name\":\"AntShare\"}]", txData.Name)
|
|
||||||
assert.Equal(t, util.Fixed8FromInt64(100000000), txData.Amount)
|
|
||||||
assert.Equal(t, uint8(0), txData.Precision)
|
|
||||||
assert.Equal(t, keys.PublicKey{}, txData.Owner)
|
|
||||||
assert.Equal(t, "Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt", address.Uint160ToString(txData.Admin))
|
|
||||||
assert.Equal(t, "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", tx.Hash().StringLE())
|
|
||||||
|
|
||||||
testserdes.EncodeDecodeBinary(t, tx, new(Transaction))
|
|
||||||
}
|
|
||||||
*/
|
|
|
@ -176,9 +176,6 @@ func (t *Transaction) decodeData(r *io.BinReader) {
|
||||||
case InvocationType:
|
case InvocationType:
|
||||||
t.Data = &InvocationTX{}
|
t.Data = &InvocationTX{}
|
||||||
t.Data.(*InvocationTX).DecodeBinary(r)
|
t.Data.(*InvocationTX).DecodeBinary(r)
|
||||||
case RegisterType:
|
|
||||||
t.Data = &RegisterTX{}
|
|
||||||
t.Data.(*RegisterTX).DecodeBinary(r)
|
|
||||||
default:
|
default:
|
||||||
r.Err = fmt.Errorf("invalid TX type %x", t.Type)
|
r.Err = fmt.Errorf("invalid TX type %x", t.Type)
|
||||||
}
|
}
|
||||||
|
@ -302,7 +299,6 @@ type transactionJSON struct {
|
||||||
Scripts []Witness `json:"scripts"`
|
Scripts []Witness `json:"scripts"`
|
||||||
|
|
||||||
Script string `json:"script,omitempty"`
|
Script string `json:"script,omitempty"`
|
||||||
Asset *registeredAsset `json:"asset,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON implements json.Marshaler interface.
|
// MarshalJSON implements json.Marshaler interface.
|
||||||
|
@ -326,16 +322,6 @@ func (t *Transaction) MarshalJSON() ([]byte, error) {
|
||||||
switch t.Type {
|
switch t.Type {
|
||||||
case InvocationType:
|
case InvocationType:
|
||||||
tx.Script = hex.EncodeToString(t.Data.(*InvocationTX).Script)
|
tx.Script = hex.EncodeToString(t.Data.(*InvocationTX).Script)
|
||||||
case RegisterType:
|
|
||||||
transaction := *t.Data.(*RegisterTX)
|
|
||||||
tx.Asset = ®isteredAsset{
|
|
||||||
AssetType: transaction.AssetType,
|
|
||||||
Name: json.RawMessage(transaction.Name),
|
|
||||||
Amount: transaction.Amount,
|
|
||||||
Precision: transaction.Precision,
|
|
||||||
Owner: transaction.Owner,
|
|
||||||
Admin: address.Uint160ToString(transaction.Admin),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return json.Marshal(tx)
|
return json.Marshal(tx)
|
||||||
}
|
}
|
||||||
|
@ -371,19 +357,6 @@ func (t *Transaction) UnmarshalJSON(data []byte) error {
|
||||||
t.Data = &InvocationTX{
|
t.Data = &InvocationTX{
|
||||||
Script: bytes,
|
Script: bytes,
|
||||||
}
|
}
|
||||||
case RegisterType:
|
|
||||||
admin, err := address.StringToUint160(tx.Asset.Admin)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t.Data = &RegisterTX{
|
|
||||||
AssetType: tx.Asset.AssetType,
|
|
||||||
Name: string(tx.Asset.Name),
|
|
||||||
Amount: tx.Asset.Amount,
|
|
||||||
Precision: tx.Asset.Precision,
|
|
||||||
Owner: tx.Asset.Owner,
|
|
||||||
Admin: admin,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if t.Hash() != tx.TxID {
|
if t.Hash() != tx.TxID {
|
||||||
return errors.New("txid doesn't match transaction hash")
|
return errors.New("txid doesn't match transaction hash")
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
||||||
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
"github.com/nspcc-dev/neo-go/pkg/internal/testserdes"
|
||||||
"github.com/nspcc-dev/neo-go/pkg/util"
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -103,33 +102,3 @@ func TestMarshalUnmarshalJSONInvocationTX(t *testing.T) {
|
||||||
|
|
||||||
testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction))
|
testserdes.MarshalUnmarshalJSON(t, tx, new(Transaction))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarshalUnmarshalJSONRegisterTX(t *testing.T) {
|
|
||||||
tx := &Transaction{
|
|
||||||
Type: RegisterType,
|
|
||||||
Version: 5,
|
|
||||||
Data: &RegisterTX{
|
|
||||||
AssetType: 0,
|
|
||||||
Name: `[{"lang":"zh-CN","name":"小蚁股"},{"lang":"en","name":"AntShare"}]`,
|
|
||||||
Amount: 1000000,
|
|
||||||
Precision: 0,
|
|
||||||
Owner: keys.PublicKey{},
|
|
||||||
Admin: util.Uint160{},
|
|
||||||
},
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
|
@ -11,15 +11,12 @@ type TXType uint8
|
||||||
|
|
||||||
// Constants for all valid transaction types.
|
// Constants for all valid transaction types.
|
||||||
const (
|
const (
|
||||||
RegisterType TXType = 0x40
|
|
||||||
InvocationType TXType = 0xd1
|
InvocationType TXType = 0xd1
|
||||||
)
|
)
|
||||||
|
|
||||||
// String implements the stringer interface.
|
// String implements the stringer interface.
|
||||||
func (t TXType) String() string {
|
func (t TXType) String() string {
|
||||||
switch t {
|
switch t {
|
||||||
case RegisterType:
|
|
||||||
return "RegisterTransaction"
|
|
||||||
case InvocationType:
|
case InvocationType:
|
||||||
return "InvocationTransaction"
|
return "InvocationTransaction"
|
||||||
default:
|
default:
|
||||||
|
@ -46,8 +43,6 @@ func (t *TXType) UnmarshalJSON(data []byte) error {
|
||||||
// TXTypeFromString searches for TXType by string name.
|
// TXTypeFromString searches for TXType by string name.
|
||||||
func TXTypeFromString(jsonString string) (TXType, error) {
|
func TXTypeFromString(jsonString string) (TXType, error) {
|
||||||
switch jsonString = strings.TrimSpace(jsonString); jsonString {
|
switch jsonString = strings.TrimSpace(jsonString); jsonString {
|
||||||
case "RegisterTransaction":
|
|
||||||
return RegisterType, nil
|
|
||||||
case "InvocationTransaction":
|
case "InvocationTransaction":
|
||||||
return InvocationType, nil
|
return InvocationType, nil
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -89,45 +89,6 @@ func deployNativeContracts() *transaction.Transaction {
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
|
||||||
admin := hash.Hash160([]byte{byte(opcode.OLDPUSH1)})
|
|
||||||
registerTX := &transaction.RegisterTX{
|
|
||||||
AssetType: transaction.GoverningToken,
|
|
||||||
Name: "[{\"lang\":\"zh-CN\",\"name\":\"小蚁股\"},{\"lang\":\"en\",\"name\":\"AntShare\"}]",
|
|
||||||
Amount: util.Fixed8FromInt64(100000000),
|
|
||||||
Precision: 0,
|
|
||||||
Admin: admin,
|
|
||||||
}
|
|
||||||
|
|
||||||
governingTokenTX = *transaction.NewRegisterTX(registerTX)
|
|
||||||
// TODO NEO3.0: nonce should be constant to avoid variability of token hash
|
|
||||||
governingTokenTX.Nonce = 0
|
|
||||||
governingTokenTX.Sender = hash.Hash160([]byte{byte(opcode.OLDPUSH1)})
|
|
||||||
|
|
||||||
admin = hash.Hash160([]byte{0x00})
|
|
||||||
registerTX = &transaction.RegisterTX{
|
|
||||||
AssetType: transaction.UtilityToken,
|
|
||||||
Name: "[{\"lang\":\"zh-CN\",\"name\":\"小蚁币\"},{\"lang\":\"en\",\"name\":\"AntCoin\"}]",
|
|
||||||
Amount: calculateUtilityAmount(),
|
|
||||||
Precision: 8,
|
|
||||||
Admin: admin,
|
|
||||||
}
|
|
||||||
utilityTokenTX = *transaction.NewRegisterTX(registerTX)
|
|
||||||
// TODO NEO3.0: nonce should be constant to avoid variability of token hash
|
|
||||||
utilityTokenTX.Nonce = 0
|
|
||||||
utilityTokenTX.Sender = hash.Hash160([]byte{byte(opcode.OLDPUSH1)})
|
|
||||||
}
|
|
||||||
|
|
||||||
// GoverningTokenID returns the governing token (NEO) hash.
|
|
||||||
func GoverningTokenID() util.Uint256 {
|
|
||||||
return governingTokenTX.Hash()
|
|
||||||
}
|
|
||||||
|
|
||||||
// UtilityTokenID returns the utility token (GAS) hash.
|
|
||||||
func UtilityTokenID() util.Uint256 {
|
|
||||||
return utilityTokenTX.Hash()
|
|
||||||
}
|
|
||||||
|
|
||||||
func getValidators(cfg config.ProtocolConfiguration) ([]*keys.PublicKey, error) {
|
func getValidators(cfg config.ProtocolConfiguration) ([]*keys.PublicKey, error) {
|
||||||
validators := make([]*keys.PublicKey, len(cfg.StandbyValidators))
|
validators := make([]*keys.PublicKey, len(cfg.StandbyValidators))
|
||||||
for i, pubKeyStr := range cfg.StandbyValidators {
|
for i, pubKeyStr := range cfg.StandbyValidators {
|
||||||
|
|
|
@ -42,19 +42,3 @@ func TestGetConsensusAddressMainNet(t *testing.T) {
|
||||||
assert.Equal(t, consensusScript, script.String())
|
assert.Equal(t, consensusScript, script.String())
|
||||||
assert.Equal(t, consensusAddr, address.Uint160ToString(script))
|
assert.Equal(t, consensusAddr, address.Uint160ToString(script))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUtilityTokenTX(t *testing.T) {
|
|
||||||
//TODO: After we added Nonce field to transaction.Transaction, UtilityTockenTx hash
|
|
||||||
// has been changed. Update it for better times.
|
|
||||||
// Old hash is "602c79718b16e442de58778e148d0b1084e3b2dffd5de6b7b16cee7969282de7"
|
|
||||||
expect := "f882fb865bab84b99623f21eedd902286af7da8d8a4609d7acefce04c851dc1c"
|
|
||||||
assert.Equal(t, expect, UtilityTokenID().StringLE())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGoverningTokenTX(t *testing.T) {
|
|
||||||
//TODO: After we added Nonce field to transaction.Transaction, GoveringTockenTx hash
|
|
||||||
// has been changed. Update it for better times.
|
|
||||||
// Old hash is "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b"
|
|
||||||
expect := "1a5e0e3eac2abced7de9ee2de0820a5c85e63756fcdfc29b82fead86a7c07c78"
|
|
||||||
assert.Equal(t, expect, GoverningTokenID().StringLE())
|
|
||||||
}
|
|
||||||
|
|
|
@ -24,7 +24,6 @@ func GetHash(t Transaction) []byte {
|
||||||
// GetType returns the type of the given transaction. Possible values:
|
// GetType returns the type of the given transaction. Possible values:
|
||||||
// MinerTransaction = 0x00
|
// MinerTransaction = 0x00
|
||||||
// EnrollmentTransaction = 0x20
|
// EnrollmentTransaction = 0x20
|
||||||
// RegisterTransaction = 0x40
|
|
||||||
// StateType = 0x90
|
// StateType = 0x90
|
||||||
// AgencyTransaction = 0xb0
|
// AgencyTransaction = 0xb0
|
||||||
// PublishTransaction = 0xd0
|
// PublishTransaction = 0xd0
|
||||||
|
|
Loading…
Reference in a new issue