From f1856bfa8b1baf408967970f61ad03f820c14d2a Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 9 Dec 2019 18:33:04 +0300 Subject: [PATCH] core/tx: remove publickey indirection from assets and txes It makes very little sense having pointers here, these structures MUST have some kind of key and this key is not gonna be wandering somewhere on its own. Fixes a part of #519. --- pkg/core/asset_state.go | 3 +-- pkg/core/asset_state_test.go | 3 --- pkg/core/blockchain.go | 2 +- pkg/core/interop_neo.go | 2 +- pkg/core/interop_neo_test.go | 2 +- pkg/core/transaction/enrollment.go | 3 +-- pkg/core/transaction/register.go | 3 +-- pkg/core/transaction/register_test.go | 3 +-- pkg/core/util.go | 2 -- 9 files changed, 7 insertions(+), 16 deletions(-) diff --git a/pkg/core/asset_state.go b/pkg/core/asset_state.go index fc0fe09e7..6af69172c 100644 --- a/pkg/core/asset_state.go +++ b/pkg/core/asset_state.go @@ -43,7 +43,7 @@ type AssetState struct { Precision uint8 FeeMode uint8 FeeAddress util.Uint160 - Owner *keys.PublicKey + Owner keys.PublicKey Admin util.Uint160 Issuer util.Uint160 Expiration uint32 @@ -63,7 +63,6 @@ func (a *AssetState) DecodeBinary(br *io.BinReader) { br.ReadLE(&a.FeeMode) br.ReadBytes(a.FeeAddress[:]) - a.Owner = &keys.PublicKey{} a.Owner.DecodeBinary(br) br.ReadBytes(a.Admin[:]) br.ReadBytes(a.Issuer[:]) diff --git a/pkg/core/asset_state_test.go b/pkg/core/asset_state_test.go index 8fbfb3791..ac9d1ef7b 100644 --- a/pkg/core/asset_state_test.go +++ b/pkg/core/asset_state_test.go @@ -5,7 +5,6 @@ import ( "github.com/CityOfZion/neo-go/pkg/core/storage" "github.com/CityOfZion/neo-go/pkg/core/transaction" - "github.com/CityOfZion/neo-go/pkg/crypto/keys" "github.com/CityOfZion/neo-go/pkg/io" "github.com/CityOfZion/neo-go/pkg/util" "github.com/stretchr/testify/assert" @@ -20,7 +19,6 @@ func TestEncodeDecodeAssetState(t *testing.T) { Available: util.Fixed8(100), Precision: 0, FeeMode: feeMode, - Owner: &keys.PublicKey{}, Admin: randomUint160(), Issuer: randomUint160(), Expiration: 10, @@ -47,7 +45,6 @@ func TestPutGetAssetState(t *testing.T) { Available: util.Fixed8(100), Precision: 8, FeeMode: feeMode, - Owner: &keys.PublicKey{}, Admin: randomUint160(), Issuer: randomUint160(), Expiration: 10, diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index 6544ebc4b..0a75d9d2a 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1340,7 +1340,7 @@ func processStateTX(chainState *BlockChainState, tx *transaction.StateTX) error } func processEnrollmentTX(chainState *BlockChainState, tx *transaction.EnrollmentTX) error { - validatorState, err := chainState.validators.getAndUpdate(chainState.store, tx.PublicKey) + validatorState, err := chainState.validators.getAndUpdate(chainState.store, &tx.PublicKey) if err != nil { return err } diff --git a/pkg/core/interop_neo.go b/pkg/core/interop_neo.go index da688b9cc..17c100e1c 100644 --- a/pkg/core/interop_neo.go +++ b/pkg/core/interop_neo.go @@ -615,7 +615,7 @@ func (ic *interopContext) assetCreate(v *vm.VM) error { Name: name, Amount: amount, Precision: precision, - Owner: owner, + Owner: *owner, Admin: admin, Issuer: issuer, Expiration: ic.bc.BlockHeight() + DefaultAssetLifetime, diff --git a/pkg/core/interop_neo_test.go b/pkg/core/interop_neo_test.go index c1c378cd9..1fee8ae98 100644 --- a/pkg/core/interop_neo_test.go +++ b/pkg/core/interop_neo_test.go @@ -348,7 +348,7 @@ func createVMAndAssetState(t *testing.T) (*vm.VM, *AssetState, *interopContext) Precision: 1, FeeMode: 1, FeeAddress: randomUint160(), - Owner: &keys.PublicKey{X: big.NewInt(1), Y: big.NewInt(1)}, + Owner: keys.PublicKey{X: big.NewInt(1), Y: big.NewInt(1)}, Admin: randomUint160(), Issuer: randomUint160(), Expiration: 10, diff --git a/pkg/core/transaction/enrollment.go b/pkg/core/transaction/enrollment.go index f61269ba9..0d7c8a0e4 100644 --- a/pkg/core/transaction/enrollment.go +++ b/pkg/core/transaction/enrollment.go @@ -12,12 +12,11 @@ import ( // 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 + PublicKey keys.PublicKey } // DecodeBinary implements Serializable interface. func (tx *EnrollmentTX) DecodeBinary(r *io.BinReader) { - tx.PublicKey = &keys.PublicKey{} tx.PublicKey.DecodeBinary(r) } diff --git a/pkg/core/transaction/register.go b/pkg/core/transaction/register.go index bba131263..2c7758e84 100644 --- a/pkg/core/transaction/register.go +++ b/pkg/core/transaction/register.go @@ -23,7 +23,7 @@ type RegisterTX struct { Precision uint8 // Public key of the owner. - Owner *keys.PublicKey + Owner keys.PublicKey Admin util.Uint160 } @@ -37,7 +37,6 @@ func (tx *RegisterTX) DecodeBinary(br *io.BinReader) { br.ReadLE(&tx.Amount) br.ReadLE(&tx.Precision) - tx.Owner = &keys.PublicKey{} tx.Owner.DecodeBinary(br) br.ReadBytes(tx.Admin[:]) diff --git a/pkg/core/transaction/register_test.go b/pkg/core/transaction/register_test.go index dd9aa0b02..7d635802d 100644 --- a/pkg/core/transaction/register_test.go +++ b/pkg/core/transaction/register_test.go @@ -21,7 +21,6 @@ func TestRegisterTX(t *testing.T) { Name: "this is some token I created", Amount: util.Fixed8FromInt64(1000000), Precision: 8, - Owner: &keys.PublicKey{}, Admin: someuint160, }, } @@ -58,7 +57,7 @@ func TestDecodeRegisterTXFromRawString(t *testing.T) { 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, keys.PublicKey{}, txData.Owner) assert.Equal(t, "Abf2qMs1pzQb8kYk9RuxtUb9jtRKJVuBJt", crypto.AddressFromUint160(txData.Admin)) assert.Equal(t, "c56f33fc6ecfcd0c225c4ab356fee59390af8560be0e930faebe74a6daff7c9b", tx.Hash().StringLE()) diff --git a/pkg/core/util.go b/pkg/core/util.go index 8da60beab..c553f5ef0 100644 --- a/pkg/core/util.go +++ b/pkg/core/util.go @@ -98,7 +98,6 @@ func governingTokenTX() *transaction.Transaction { Name: "[{\"lang\":\"zh-CN\",\"name\":\"小蚁股\"},{\"lang\":\"en\",\"name\":\"AntShare\"}]", Amount: util.Fixed8FromInt64(100000000), Precision: 0, - Owner: &keys.PublicKey{}, Admin: admin, } @@ -121,7 +120,6 @@ func utilityTokenTX() *transaction.Transaction { Name: "[{\"lang\":\"zh-CN\",\"name\":\"小蚁币\"},{\"lang\":\"en\",\"name\":\"AntCoin\"}]", Amount: calculateUtilityAmount(), Precision: 8, - Owner: &keys.PublicKey{}, Admin: admin, } tx := &transaction.Transaction{