mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 23:02:27 +00:00
transaction: drop Issue TX support
This commit is contained in:
parent
f445f7c602
commit
169c5ae775
22 changed files with 8 additions and 141 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
|
||||
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
||||
"github.com/nspcc-dev/neo-go/pkg/vm/opcode"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -84,7 +85,7 @@ func newDumbBlock() *Block {
|
|||
Nonce: 1111,
|
||||
},
|
||||
Transactions: []*transaction.Transaction{
|
||||
transaction.NewIssueTX(),
|
||||
transaction.NewInvocationTX([]byte{byte(opcode.PUSH1)}, 0),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -643,19 +643,6 @@ func (bc *Blockchain) storeBlock(block *block.Block) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case *transaction.IssueTX:
|
||||
for _, res := range bc.GetTransactionResults(tx) {
|
||||
if res.Amount < 0 {
|
||||
asset, err := cache.GetAssetState(res.AssetID)
|
||||
if asset == nil || err != nil {
|
||||
return fmt.Errorf("issue failed: no asset %s or error %s", res.AssetID, err)
|
||||
}
|
||||
asset.Available -= res.Amount
|
||||
if err := cache.PutAssetState(asset); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
case *transaction.InvocationTX:
|
||||
systemInterop := bc.newInteropContext(trigger.Application, cache, block, tx)
|
||||
v := SpawnVM(systemInterop)
|
||||
|
@ -1437,26 +1424,8 @@ func (bc *Blockchain) verifyResults(t *transaction.Transaction, results []*trans
|
|||
return errors.New("tx destroys non-utility token")
|
||||
}
|
||||
|
||||
switch t.Type {
|
||||
case transaction.IssueType:
|
||||
for _, r := range resultsIssue {
|
||||
if r.AssetID == UtilityTokenID() {
|
||||
return errors.New("issue tx issues utility tokens")
|
||||
}
|
||||
asset, err := bc.dao.GetAssetState(r.AssetID)
|
||||
if asset == nil || err != nil {
|
||||
return errors.New("invalid asset in issue tx")
|
||||
}
|
||||
if asset.Available < r.Amount {
|
||||
return errors.New("trying to issue more than available")
|
||||
}
|
||||
}
|
||||
break
|
||||
default:
|
||||
if len(resultsIssue) > 0 {
|
||||
return errors.New("non issue/miner/claim tx issues tokens")
|
||||
}
|
||||
break
|
||||
if len(resultsIssue) > 0 {
|
||||
return errors.New("non issue/miner/claim tx issues tokens")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -1547,16 +1516,6 @@ func (bc *Blockchain) GetScriptHashesForVerifying(t *transaction.Transaction) ([
|
|||
hashes[c.Account] = true
|
||||
}
|
||||
switch t.Type {
|
||||
case transaction.IssueType:
|
||||
for _, res := range refsAndOutsToResults(references, t.Outputs) {
|
||||
if res.Amount < 0 {
|
||||
asset, err := bc.dao.GetAssetState(res.AssetID)
|
||||
if asset == nil || err != nil {
|
||||
return nil, errors.New("invalid asset in issue tx")
|
||||
}
|
||||
hashes[asset.Issuer] = true
|
||||
}
|
||||
}
|
||||
case transaction.RegisterType:
|
||||
reg := t.Data.(*transaction.RegisterTX)
|
||||
hashes[reg.Owner.GetScriptHash()] = true
|
||||
|
|
|
@ -220,7 +220,7 @@ func TestGetCurrentHeaderHeight_Store(t *testing.T) {
|
|||
|
||||
func TestStoreAsTransaction(t *testing.T) {
|
||||
dao := NewSimple(storage.NewMemoryStore())
|
||||
tx := transaction.NewIssueTX()
|
||||
tx := transaction.NewInvocationTX([]byte{byte(opcode.PUSH1)}, 1)
|
||||
hash := tx.Hash()
|
||||
err := dao.StoreAsTransaction(tx, 0)
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -138,7 +138,7 @@ func newDumbBlock() *block.Block {
|
|||
Nonce: 1111,
|
||||
},
|
||||
Transactions: []*transaction.Transaction{
|
||||
{Type: transaction.IssueType},
|
||||
transaction.NewInvocationTX([]byte{byte(opcode.PUSH1)}, 0),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -353,17 +353,6 @@ func (mp *Pool) checkTxConflicts(tx *transaction.Transaction, fee Feer) bool {
|
|||
if !mp.checkBalanceAndUpdate(tx, fee) {
|
||||
return false
|
||||
}
|
||||
switch tx.Type {
|
||||
case transaction.IssueType:
|
||||
// It's a hack, because technically we could check for
|
||||
// available asset amount, but these transactions are so rare
|
||||
// that no one really cares about this restriction.
|
||||
for i := range mp.verifiedTxes {
|
||||
if mp.verifiedTxes[i].txn.Type == transaction.IssueType {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -129,29 +129,6 @@ func TestMemPoolVerifyInputs(t *testing.T) {
|
|||
require.Error(t, mp.Add(tx3, &FeerStub{}))
|
||||
}
|
||||
|
||||
func TestMemPoolVerifyIssue(t *testing.T) {
|
||||
mp := NewMemPool(50)
|
||||
tx1 := newIssueTX()
|
||||
require.Equal(t, true, mp.Verify(tx1, &FeerStub{}))
|
||||
require.NoError(t, mp.Add(tx1, &FeerStub{}))
|
||||
|
||||
tx2 := newIssueTX()
|
||||
require.Equal(t, false, mp.Verify(tx2, &FeerStub{}))
|
||||
require.Error(t, mp.Add(tx2, &FeerStub{}))
|
||||
}
|
||||
|
||||
func newIssueTX() *transaction.Transaction {
|
||||
tx := transaction.NewIssueTX()
|
||||
tx.Outputs = []transaction.Output{
|
||||
{
|
||||
AssetID: random.Uint256(),
|
||||
Amount: util.Fixed8FromInt64(42),
|
||||
ScriptHash: random.Uint160(),
|
||||
},
|
||||
}
|
||||
return tx
|
||||
}
|
||||
|
||||
func TestOverCapacity(t *testing.T) {
|
||||
var fs = &FeerStub{lowPriority: true}
|
||||
const mempoolSize = 10
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package transaction
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/pkg/io"
|
||||
)
|
||||
|
||||
// IssueTX represents a issue transaction.
|
||||
// This TX has not special attributes.
|
||||
type IssueTX struct{}
|
||||
|
||||
// NewIssueTX creates Transaction of IssueType type.
|
||||
func NewIssueTX() *Transaction {
|
||||
return &Transaction{
|
||||
Type: IssueType,
|
||||
Version: 0,
|
||||
Nonce: rand.Uint32(),
|
||||
Data: &IssueTX{},
|
||||
Attributes: []Attribute{},
|
||||
Cosigners: []Cosigner{},
|
||||
Inputs: []Input{},
|
||||
Outputs: []Output{},
|
||||
Scripts: []Witness{},
|
||||
Trimmed: false,
|
||||
}
|
||||
}
|
||||
|
||||
// DecodeBinary implements Serializable interface.
|
||||
func (tx *IssueTX) DecodeBinary(r *io.BinReader) {
|
||||
}
|
||||
|
||||
// EncodeBinary implements Serializable interface.
|
||||
func (tx *IssueTX) EncodeBinary(w *io.BinWriter) {
|
||||
}
|
|
@ -179,9 +179,6 @@ func (t *Transaction) decodeData(r *io.BinReader) {
|
|||
case RegisterType:
|
||||
t.Data = &RegisterTX{}
|
||||
t.Data.(*RegisterTX).DecodeBinary(r)
|
||||
case IssueType:
|
||||
t.Data = &IssueTX{}
|
||||
t.Data.(*IssueTX).DecodeBinary(r)
|
||||
default:
|
||||
r.Err = fmt.Errorf("invalid TX type %x", t.Type)
|
||||
}
|
||||
|
@ -387,8 +384,6 @@ func (t *Transaction) UnmarshalJSON(data []byte) error {
|
|||
Owner: tx.Asset.Owner,
|
||||
Admin: admin,
|
||||
}
|
||||
case IssueType:
|
||||
t.Data = &IssueTX{}
|
||||
}
|
||||
if t.Hash() != tx.TxID {
|
||||
return errors.New("txid doesn't match transaction hash")
|
||||
|
|
|
@ -11,7 +11,6 @@ type TXType uint8
|
|||
|
||||
// Constants for all valid transaction types.
|
||||
const (
|
||||
IssueType TXType = 0x01
|
||||
RegisterType TXType = 0x40
|
||||
InvocationType TXType = 0xd1
|
||||
)
|
||||
|
@ -19,8 +18,6 @@ const (
|
|||
// String implements the stringer interface.
|
||||
func (t TXType) String() string {
|
||||
switch t {
|
||||
case IssueType:
|
||||
return "IssueTransaction"
|
||||
case RegisterType:
|
||||
return "RegisterTransaction"
|
||||
case InvocationType:
|
||||
|
@ -49,8 +46,6 @@ func (t *TXType) UnmarshalJSON(data []byte) error {
|
|||
// TXTypeFromString searches for TXType by string name.
|
||||
func TXTypeFromString(jsonString string) (TXType, error) {
|
||||
switch jsonString = strings.TrimSpace(jsonString); jsonString {
|
||||
case "IssueTransaction":
|
||||
return IssueType, nil
|
||||
case "RegisterTransaction":
|
||||
return RegisterType, nil
|
||||
case "InvocationTransaction":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue