From fb989c7726aa9565c5d24c13d60c7b5c1e40a4ac Mon Sep 17 00:00:00 2001 From: Wolfgang Welz <welzwo@gmail.com> Date: Tue, 23 Jun 2020 19:15:52 +0200 Subject: [PATCH] remove unused code (#534) --- go.mod | 1 - packages/client/address.go | 30 - packages/client/bundle.go | 39 -- packages/client/bundlefactory.go | 145 ----- packages/client/seed.go | 57 -- packages/model/approvers/approvers.go | 149 ----- packages/model/approvers/approvers_test.go | 37 -- packages/model/approvers/constants.go | 14 - packages/model/bundle/bundle.go | 183 ------ packages/model/bundle/bundle_test.go | 56 -- packages/model/bundle/constants.go | 20 - packages/model/error.go | 8 - packages/model/meta_transaction/constants.go | 41 -- .../meta_transaction/meta_transaction.go | 577 ------------------ .../meta_transaction/meta_transaction_test.go | 71 --- packages/model/transactionmetadata/const.go | 21 - .../transactionmetadata.go | 277 --------- packages/model/value_transaction/constants.go | 31 - .../value_transaction/value_transaction.go | 257 -------- .../value_transaction_test.go | 25 - 20 files changed, 2039 deletions(-) delete mode 100644 packages/client/address.go delete mode 100644 packages/client/bundle.go delete mode 100644 packages/client/bundlefactory.go delete mode 100644 packages/client/seed.go delete mode 100644 packages/model/approvers/approvers.go delete mode 100644 packages/model/approvers/approvers_test.go delete mode 100644 packages/model/approvers/constants.go delete mode 100644 packages/model/bundle/bundle.go delete mode 100644 packages/model/bundle/bundle_test.go delete mode 100644 packages/model/bundle/constants.go delete mode 100644 packages/model/error.go delete mode 100644 packages/model/meta_transaction/constants.go delete mode 100644 packages/model/meta_transaction/meta_transaction.go delete mode 100644 packages/model/meta_transaction/meta_transaction_test.go delete mode 100644 packages/model/transactionmetadata/const.go delete mode 100644 packages/model/transactionmetadata/transactionmetadata.go delete mode 100644 packages/model/value_transaction/constants.go delete mode 100644 packages/model/value_transaction/value_transaction.go delete mode 100644 packages/model/value_transaction/value_transaction_test.go diff --git a/go.mod b/go.mod index 4aac7d77..9124db72 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/golang/protobuf v1.4.2 github.com/gorilla/websocket v1.4.2 github.com/iotaledger/hive.go v0.0.0-20200622211038-2db5f8e0532d - github.com/iotaledger/iota.go v1.0.0-beta.15 github.com/labstack/echo v3.3.10+incompatible github.com/labstack/gommon v0.3.0 github.com/magiconair/properties v1.8.1 diff --git a/packages/client/address.go b/packages/client/address.go deleted file mode 100644 index 9107cd39..00000000 --- a/packages/client/address.go +++ /dev/null @@ -1,30 +0,0 @@ -package client - -import ( - "github.com/iotaledger/iota.go/consts" - "github.com/iotaledger/iota.go/trinary" -) - -type Address struct { - trytes trinary.Trytes - securityLevel consts.SecurityLevel - privateKey trinary.Trits -} - -func NewAddress(trytes trinary.Trytes) *Address { - return &Address{ - trytes: trytes, - } -} - -func (address *Address) GetTrytes() trinary.Trytes { - return address.trytes -} - -func (address *Address) GetSecurityLevel() consts.SecurityLevel { - return address.securityLevel -} - -func (address *Address) GetPrivateKey() trinary.Trits { - return address.privateKey -} diff --git a/packages/client/bundle.go b/packages/client/bundle.go deleted file mode 100644 index da25cb6f..00000000 --- a/packages/client/bundle.go +++ /dev/null @@ -1,39 +0,0 @@ -package client - -import ( - "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/iota.go/curl" - "github.com/iotaledger/iota.go/trinary" -) - -type Bundle struct { - essenceHash trinary.Trytes - transactions []*value_transaction.ValueTransaction -} - -func (bundle *Bundle) GetEssenceHash() trinary.Trytes { - return bundle.essenceHash -} - -func (bundle *Bundle) GetTransactions() []*value_transaction.ValueTransaction { - return bundle.transactions -} - -func CalculateBundleHash(transactions []*value_transaction.ValueTransaction) trinary.Trytes { - var lastInputAddress trinary.Trytes - - var concatenatedBundleEssences = make(trinary.Trits, len(transactions)*value_transaction.BUNDLE_ESSENCE_SIZE) - for i, bundleTransaction := range transactions { - if bundleTransaction.GetValue() <= 0 { - lastInputAddress = bundleTransaction.GetAddress() - } - - copy(concatenatedBundleEssences[value_transaction.BUNDLE_ESSENCE_SIZE*i:value_transaction.BUNDLE_ESSENCE_SIZE*(i+1)], bundleTransaction.GetBundleEssence(lastInputAddress != bundleTransaction.GetAddress())) - } - - bundleHash, err := curl.HashTrits(concatenatedBundleEssences) - if err != nil { - panic(err) - } - return trinary.MustTritsToTrytes(bundleHash) -} diff --git a/packages/client/bundlefactory.go b/packages/client/bundlefactory.go deleted file mode 100644 index dc2d6534..00000000 --- a/packages/client/bundlefactory.go +++ /dev/null @@ -1,145 +0,0 @@ -package client - -import ( - "github.com/iotaledger/goshimmer/packages/model/value_transaction" - "github.com/iotaledger/iota.go/consts" - "github.com/iotaledger/iota.go/converter" - "github.com/iotaledger/iota.go/signing" - "github.com/iotaledger/iota.go/trinary" -) - -type BundleFactory struct { - inputs []bundleFactoryInputEntry - outputs []bundleFactoryOutputEntry -} - -func NewBundleFactory() *BundleFactory { - return &BundleFactory{ - inputs: make([]bundleFactoryInputEntry, 0), - outputs: make([]bundleFactoryOutputEntry, 0), - } -} - -func (bundleFactory *BundleFactory) AddInput(address *Address, value int64) { - bundleFactory.inputs = append(bundleFactory.inputs, bundleFactoryInputEntry{ - address: address, - value: value, - }) -} - -func (bundleFactory *BundleFactory) AddOutput(address *Address, value int64, message ...string) { - if len(message) >= 1 { - messageTrytes, err := converter.ASCIIToTrytes(message[0]) - if err != nil { - panic(err) - } - - bundleFactory.outputs = append(bundleFactory.outputs, bundleFactoryOutputEntry{ - address: address, - value: value, - message: trinary.MustPad(messageTrytes, value_transaction.SIGNATURE_MESSAGE_FRAGMENT_SIZE), - }) - } else { - bundleFactory.outputs = append(bundleFactory.outputs, bundleFactoryOutputEntry{ - address: address, - value: value, - }) - } -} - -func (bundleFactory *BundleFactory) GenerateBundle(branchTransactionHash trinary.Trytes, trunkTransactionHash trinary.Trytes) *Bundle { - transactions := bundleFactory.generateTransactions() - - bundleHash := bundleFactory.signTransactions(transactions) - - bundleFactory.connectTransactions(transactions, branchTransactionHash, trunkTransactionHash) - - return &Bundle{ - essenceHash: bundleHash, - transactions: transactions, - } -} - -func (bundleFactory *BundleFactory) generateTransactions() []*value_transaction.ValueTransaction { - transactions := make([]*value_transaction.ValueTransaction, 0) - - for _, input := range bundleFactory.inputs { - transaction := value_transaction.New() - transaction.SetValue(input.value) - transaction.SetAddress(input.address.trytes) - - transactions = append(transactions, transaction) - - for i := 1; i < int(input.address.securityLevel); i++ { - transaction := value_transaction.New() - transaction.SetValue(0) - transaction.SetAddress(input.address.trytes) - - transactions = append(transactions, transaction) - } - } - - for _, output := range bundleFactory.outputs { - transaction := value_transaction.New() - transaction.SetValue(output.value) - transaction.SetAddress(output.address.trytes) - - if len(output.message) != 0 { - transaction.SetSignatureMessageFragment(output.message) - } - - transactions = append(transactions, transaction) - } - - transactions[0].SetHead(true) - transactions[len(transactions)-1].SetTail(true) - - return transactions -} - -func (bundleFactory *BundleFactory) signTransactions(transactions []*value_transaction.ValueTransaction) trinary.Trytes { - bundleHash := CalculateBundleHash(transactions) - normalizedBundleHash := signing.NormalizedBundleHash(bundleHash) - - signedTransactions := 0 - for _, input := range bundleFactory.inputs { - securityLevel := input.address.securityLevel - privateKey := input.address.privateKey - - for i := 0; i < int(securityLevel); i++ { - signedFragTrits, _ := signing.SignatureFragment( - normalizedBundleHash[i*consts.HashTrytesSize/3:(i+1)*consts.HashTrytesSize/3], - privateKey[i*consts.KeyFragmentLength:(i+1)*consts.KeyFragmentLength], - ) - - transactions[signedTransactions].SetSignatureMessageFragment(trinary.MustTritsToTrytes(signedFragTrits)) - - signedTransactions++ - } - } - - return bundleHash -} - -func (bundleFactory *BundleFactory) connectTransactions(transactions []*value_transaction.ValueTransaction, branchTransactionHash trinary.Trytes, trunkTransactionHash trinary.Trytes) { - transactionCount := len(transactions) - - transactions[transactionCount-1].SetBranchTransactionHash(branchTransactionHash) - transactions[transactionCount-1].SetTrunkTransactionHash(trunkTransactionHash) - - for i := transactionCount - 2; i >= 0; i-- { - transactions[i].SetBranchTransactionHash(branchTransactionHash) - transactions[i].SetTrunkTransactionHash(transactions[i+1].GetHash()) - } -} - -type bundleFactoryInputEntry struct { - address *Address - value int64 -} - -type bundleFactoryOutputEntry struct { - address *Address - value int64 - message trinary.Trytes -} diff --git a/packages/client/seed.go b/packages/client/seed.go deleted file mode 100644 index 0f7b8443..00000000 --- a/packages/client/seed.go +++ /dev/null @@ -1,57 +0,0 @@ -package client - -import ( - "github.com/iotaledger/iota.go/address" - "github.com/iotaledger/iota.go/consts" - "github.com/iotaledger/iota.go/kerl" - "github.com/iotaledger/iota.go/signing" - "github.com/iotaledger/iota.go/signing/key" - "github.com/iotaledger/iota.go/trinary" -) - -type Seed struct { - trytes trinary.Trytes - securityLevel consts.SecurityLevel - subSeeds map[uint64]trinary.Trits -} - -func NewSeed(trytes trinary.Trytes, securityLevel consts.SecurityLevel) *Seed { - return &Seed{ - trytes: trytes, - securityLevel: securityLevel, - subSeeds: make(map[uint64]trinary.Trits), - } -} - -func (seed *Seed) GetAddress(index uint64) *Address { - addressTrytes, err := address.GenerateAddress(seed.trytes, index, seed.securityLevel) - if err != nil { - panic(err) - } - - privateKey, err := key.Sponge(seed.GetSubSeed(index), seed.securityLevel, kerl.NewKerl()) - if err != nil { - panic(err) - } - - return &Address{ - trytes: addressTrytes, - securityLevel: seed.securityLevel, - privateKey: privateKey, - } -} - -func (seed *Seed) GetSubSeed(index uint64) trinary.Trits { - subSeed, subSeedExists := seed.subSeeds[index] - if !subSeedExists { - generatedSubSeed, err := signing.Subseed(seed.trytes, index) - if err != nil { - panic(err) - } - subSeed = generatedSubSeed - - seed.subSeeds[index] = subSeed - } - - return subSeed -} diff --git a/packages/model/approvers/approvers.go b/packages/model/approvers/approvers.go deleted file mode 100644 index d84e0221..00000000 --- a/packages/model/approvers/approvers.go +++ /dev/null @@ -1,149 +0,0 @@ -package approvers - -import ( - "encoding/binary" - "fmt" - "sync" - - "github.com/iotaledger/goshimmer/packages/model" - "github.com/iotaledger/hive.go/typeutils" - "github.com/iotaledger/iota.go/trinary" -) - -type Approvers struct { - hash trinary.Trytes - hashes map[trinary.Trytes]bool - hashesMutex sync.RWMutex - modified bool -} - -func New(hash trinary.Trytes) *Approvers { - return &Approvers{ - hash: hash, - hashes: make(map[trinary.Trytes]bool), - modified: false, - } -} - -// region public methods with locking ////////////////////////////////////////////////////////////////////////////////// - -func (approvers *Approvers) Add(transactionHash trinary.Trytes) { - approvers.hashesMutex.Lock() - approvers.add(transactionHash) - approvers.hashesMutex.Unlock() -} - -func (approvers *Approvers) Remove(approverHash trinary.Trytes) { - approvers.hashesMutex.Lock() - approvers.remove(approverHash) - approvers.hashesMutex.Unlock() -} - -func (approvers *Approvers) GetHashes() (result []trinary.Trytes) { - approvers.hashesMutex.RLock() - result = approvers.getHashes() - approvers.hashesMutex.RUnlock() - - return -} - -func (approvers *Approvers) GetHash() (result trinary.Trytes) { - approvers.hashesMutex.RLock() - result = approvers.hash - approvers.hashesMutex.RUnlock() - - return -} - -func (approvers *Approvers) GetModified() bool { - return true -} - -func (approvers *Approvers) SetModified(modified bool) { -} - -func (approvers *Approvers) Marshal() (result []byte) { - approvers.hashesMutex.RLock() - - result = make([]byte, MARSHALED_APPROVERS_MIN_SIZE+len(approvers.hashes)*MARSHALED_APPROVERS_HASH_SIZE) - - binary.BigEndian.PutUint64(result[MARSHALED_APPROVERS_HASHES_COUNT_START:MARSHALED_APPROVERS_HASHES_COUNT_END], uint64(len(approvers.hashes))) - - copy(result[MARSHALED_APPROVERS_HASH_START:MARSHALED_APPROVERS_HASH_END], typeutils.StringToBytes(approvers.hash)) - - i := 0 - for hash := range approvers.hashes { - var HASH_START = MARSHALED_APPROVERS_HASHES_START + i*(MARSHALED_APPROVERS_HASH_SIZE) - var HASH_END = HASH_START + MARSHALED_APPROVERS_HASH_SIZE - - copy(result[HASH_START:HASH_END], typeutils.StringToBytes(hash)) - - i++ - } - - approvers.hashesMutex.RUnlock() - - return -} - -func (approvers *Approvers) Unmarshal(data []byte) error { - dataLen := len(data) - - if dataLen < MARSHALED_APPROVERS_MIN_SIZE { - return fmt.Errorf("%w: marshaled approvers are too short", model.ErrMarshalFailed) - } - - hashesCount := binary.BigEndian.Uint64(data[MARSHALED_APPROVERS_HASHES_COUNT_START:MARSHALED_APPROVERS_HASHES_COUNT_END]) - - if dataLen < MARSHALED_APPROVERS_MIN_SIZE+int(hashesCount)*MARSHALED_APPROVERS_HASH_SIZE { - return fmt.Errorf("%w: marshaled approvers are too short for %d approvers", model.ErrMarshalFailed, hashesCount) - } - - approvers.hashesMutex.Lock() - - approvers.hash = trinary.Trytes(typeutils.BytesToString(data[MARSHALED_APPROVERS_HASH_START:MARSHALED_APPROVERS_HASH_END])) - approvers.hashes = make(map[trinary.Trytes]bool, hashesCount) - for i := uint64(0); i < hashesCount; i++ { - var HASH_START = MARSHALED_APPROVERS_HASHES_START + i*(MARSHALED_APPROVERS_HASH_SIZE) - var HASH_END = HASH_START + MARSHALED_APPROVERS_HASH_SIZE - - approvers.hashes[trinary.Trytes(typeutils.BytesToString(data[HASH_START:HASH_END]))] = true - } - - approvers.hashesMutex.Unlock() - - return nil -} - -// endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// region private methods without locking ////////////////////////////////////////////////////////////////////////////// - -func (approvers *Approvers) add(transactionHash trinary.Trytes) { - if _, exists := approvers.hashes[transactionHash]; !exists { - approvers.hashes[transactionHash] = true - approvers.modified = true - } -} - -func (approvers *Approvers) remove(approverHash trinary.Trytes) { - if _, exists := approvers.hashes[approverHash]; exists { - delete(approvers.hashes, approverHash) - approvers.modified = true - } -} - -func (approvers *Approvers) getHashes() (result []trinary.Trytes) { - result = make([]trinary.Trytes, len(approvers.hashes)) - - counter := 0 - for hash := range approvers.hashes { - result[counter] = hash - - counter++ - } - - return -} - -// endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/packages/model/approvers/approvers_test.go b/packages/model/approvers/approvers_test.go deleted file mode 100644 index 926c5c07..00000000 --- a/packages/model/approvers/approvers_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package approvers - -import ( - "fmt" - "testing" - - "github.com/iotaledger/iota.go/trinary" - "github.com/magiconair/properties/assert" -) - -func TestApprovers_SettersGetters(t *testing.T) { - hashA := trinary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - hashB := trinary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - approversTest := New(hashA) - approversTest.Add(hashB) - - assert.Equal(t, approversTest.GetHash(), hashA, "hash") - assert.Equal(t, approversTest.GetHashes()[0], hashB, "hashes") -} - -func TestApprovers_MarshalUnmarshal(t *testing.T) { - hashA := trinary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - hashB := trinary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - approversTest := New(hashA) - approversTest.Add(hashB) - - approversTestBytes := approversTest.Marshal() - - var approversUnmarshaled Approvers - err := approversUnmarshaled.Unmarshal(approversTestBytes) - if err != nil { - fmt.Println(err, len(approversTestBytes)) - } - - assert.Equal(t, approversUnmarshaled.GetHash(), approversTest.GetHash(), "hash") - assert.Equal(t, approversUnmarshaled.GetHashes(), approversTest.GetHashes(), "hashes") -} diff --git a/packages/model/approvers/constants.go b/packages/model/approvers/constants.go deleted file mode 100644 index 9c777856..00000000 --- a/packages/model/approvers/constants.go +++ /dev/null @@ -1,14 +0,0 @@ -package approvers - -const ( - MARSHALED_APPROVERS_HASHES_COUNT_START = 0 - MARSHALED_APPROVERS_HASH_START = MARSHALED_APPROVERS_HASHES_COUNT_END - MARSHALED_APPROVERS_HASHES_START = MARSHALED_APPROVERS_HASH_END - - MARSHALED_APPROVERS_HASHES_COUNT_END = MARSHALED_APPROVERS_HASHES_COUNT_START + MARSHALED_APPROVERS_HASHES_COUNT_SIZE - MARSHALED_APPROVERS_HASH_END = MARSHALED_APPROVERS_HASH_START + MARSHALED_APPROVERS_HASH_SIZE - - MARSHALED_APPROVERS_HASHES_COUNT_SIZE = 8 - MARSHALED_APPROVERS_HASH_SIZE = 81 - MARSHALED_APPROVERS_MIN_SIZE = MARSHALED_APPROVERS_HASHES_COUNT_SIZE + MARSHALED_APPROVERS_HASH_SIZE -) diff --git a/packages/model/bundle/bundle.go b/packages/model/bundle/bundle.go deleted file mode 100644 index d54092ed..00000000 --- a/packages/model/bundle/bundle.go +++ /dev/null @@ -1,183 +0,0 @@ -package bundle - -import ( - "encoding/binary" - "fmt" - "sync" - "unsafe" - - "github.com/iotaledger/goshimmer/packages/model" - "github.com/iotaledger/hive.go/bitmask" - "github.com/iotaledger/hive.go/typeutils" - "github.com/iotaledger/iota.go/trinary" -) - -type Bundle struct { - hash trinary.Trytes - hashMutex sync.RWMutex - transactionHashes []trinary.Trytes - transactionHashesMutex sync.RWMutex - isValueBundle bool - isValueBundleMutex sync.RWMutex - bundleEssenceHash trinary.Trytes - bundleEssenceHashMutex sync.RWMutex - modified bool - modifiedMutex sync.RWMutex -} - -func New(headTransactionHash trinary.Trytes) (result *Bundle) { - result = &Bundle{ - hash: headTransactionHash, - } - - return -} - -func (bundle *Bundle) GetHash() (result trinary.Trytes) { - bundle.hashMutex.RLock() - result = bundle.hash - bundle.hashMutex.RUnlock() - - return -} - -func (bundle *Bundle) SetHash(hash trinary.Trytes) { - bundle.hashMutex.Lock() - bundle.hash = hash - bundle.hashMutex.Unlock() -} - -func (bundle *Bundle) GetTransactionHashes() (result []trinary.Trytes) { - bundle.transactionHashesMutex.RLock() - result = bundle.transactionHashes - bundle.transactionHashesMutex.RUnlock() - - return -} - -func (bundle *Bundle) SetTransactionHashes(transactionHashes []trinary.Trytes) { - bundle.transactionHashesMutex.Lock() - bundle.transactionHashes = transactionHashes - bundle.transactionHashesMutex.Unlock() -} - -func (bundle *Bundle) IsValueBundle() (result bool) { - bundle.isValueBundleMutex.RLock() - result = bundle.isValueBundle - bundle.isValueBundleMutex.RUnlock() - - return -} - -func (bundle *Bundle) SetValueBundle(valueBundle bool) { - bundle.isValueBundleMutex.Lock() - bundle.isValueBundle = valueBundle - bundle.isValueBundleMutex.Unlock() -} - -func (bundle *Bundle) GetBundleEssenceHash() (result trinary.Trytes) { - bundle.bundleEssenceHashMutex.RLock() - result = bundle.bundleEssenceHash - bundle.bundleEssenceHashMutex.RUnlock() - - return -} - -func (bundle *Bundle) SetBundleEssenceHash(bundleEssenceHash trinary.Trytes) { - bundle.bundleEssenceHashMutex.Lock() - bundle.bundleEssenceHash = bundleEssenceHash - bundle.bundleEssenceHashMutex.Unlock() -} - -func (bundle *Bundle) GetModified() (result bool) { - bundle.modifiedMutex.RLock() - result = bundle.modified - bundle.modifiedMutex.RUnlock() - - return -} - -func (bundle *Bundle) SetModified(modified bool) { - bundle.modifiedMutex.Lock() - bundle.modified = modified - bundle.modifiedMutex.Unlock() -} - -func (bundle *Bundle) Marshal() (result []byte) { - bundle.hashMutex.RLock() - bundle.bundleEssenceHashMutex.RLock() - bundle.isValueBundleMutex.RLock() - bundle.transactionHashesMutex.RLock() - - result = make([]byte, MARSHALED_MIN_SIZE+len(bundle.transactionHashes)*MARSHALED_TRANSACTION_HASH_SIZE) - - binary.BigEndian.PutUint64(result[MARSHALED_TRANSACTIONS_COUNT_START:MARSHALED_TRANSACTIONS_COUNT_END], uint64(len(bundle.transactionHashes))) - - copy(result[MARSHALED_HASH_START:MARSHALED_HASH_END], typeutils.StringToBytes(bundle.hash)) - copy(result[MARSHALED_BUNDLE_ESSENCE_HASH_START:MARSHALED_BUNDLE_ESSENCE_HASH_END], typeutils.StringToBytes(bundle.bundleEssenceHash)) - - var flags bitmask.BitMask - if bundle.isValueBundle { - flags = flags.SetFlag(0) - } - result[MARSHALED_FLAGS_START] = *(*byte)(unsafe.Pointer(&flags)) - - i := 0 - for _, hash := range bundle.transactionHashes { - var HASH_START = MARSHALED_APPROVERS_HASHES_START + i*(MARSHALED_TRANSACTION_HASH_SIZE) - var HASH_END = HASH_START + MARSHALED_TRANSACTION_HASH_SIZE - - copy(result[HASH_START:HASH_END], typeutils.StringToBytes(hash)) - - i++ - } - - bundle.transactionHashesMutex.RUnlock() - bundle.isValueBundleMutex.RUnlock() - bundle.bundleEssenceHashMutex.RUnlock() - bundle.hashMutex.RUnlock() - - return -} - -func (bundle *Bundle) Unmarshal(data []byte) error { - dataLen := len(data) - - if dataLen < MARSHALED_MIN_SIZE { - return fmt.Errorf("%w: marshaled bundle is too short", model.ErrMarshalFailed) - } - - hashesCount := binary.BigEndian.Uint64(data[MARSHALED_TRANSACTIONS_COUNT_START:MARSHALED_TRANSACTIONS_COUNT_END]) - - if dataLen < MARSHALED_MIN_SIZE+int(hashesCount)*MARSHALED_TRANSACTION_HASH_SIZE { - return fmt.Errorf("%w: marshaled bundle is too short for %d transactions", model.ErrMarshalFailed, hashesCount) - } - - bundle.hashMutex.Lock() - bundle.bundleEssenceHashMutex.Lock() - bundle.isValueBundleMutex.Lock() - bundle.transactionHashesMutex.Lock() - - bundle.hash = trinary.Trytes(typeutils.BytesToString(data[MARSHALED_HASH_START:MARSHALED_HASH_END])) - bundle.bundleEssenceHash = trinary.Trytes(typeutils.BytesToString(data[MARSHALED_BUNDLE_ESSENCE_HASH_START:MARSHALED_BUNDLE_ESSENCE_HASH_END])) - - flags := bitmask.BitMask(data[MARSHALED_FLAGS_START]) - if flags.HasFlag(0) { - bundle.isValueBundle = true - } - - bundle.transactionHashes = make([]trinary.Trytes, hashesCount) - for i := uint64(0); i < hashesCount; i++ { - var HASH_START = MARSHALED_APPROVERS_HASHES_START + i*(MARSHALED_TRANSACTION_HASH_SIZE) - var HASH_END = HASH_START + MARSHALED_TRANSACTION_HASH_SIZE - - bundle.transactionHashes[i] = trinary.Trytes(typeutils.BytesToString(data[HASH_START:HASH_END])) - } - - bundle.transactionHashesMutex.Unlock() - bundle.isValueBundleMutex.Unlock() - bundle.bundleEssenceHashMutex.Unlock() - bundle.hashMutex.Unlock() - - return nil -} diff --git a/packages/model/bundle/bundle_test.go b/packages/model/bundle/bundle_test.go deleted file mode 100644 index d00bb6ec..00000000 --- a/packages/model/bundle/bundle_test.go +++ /dev/null @@ -1,56 +0,0 @@ -package bundle - -import ( - "testing" - - "github.com/iotaledger/iota.go/trinary" - "github.com/magiconair/properties/assert" -) - -func TestBundle_SettersGetters(t *testing.T) { - bundleHash := trinary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - bundleEssenceHash := trinary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - transactions := []trinary.Trytes{ - bundleHash, - trinary.Trytes("C9999999999999999999999999999999999999999999999999999999999999999999999999999999F"), - } - - testBundle := New(bundleHash) - testBundle.SetTransactionHashes(transactions) - testBundle.SetBundleEssenceHash(bundleEssenceHash) - testBundle.SetValueBundle(true) - - assert.Equal(t, testBundle.GetHash(), bundleHash, "hash of source") - assert.Equal(t, testBundle.GetBundleEssenceHash(), bundleEssenceHash, "bundle essence hash of source") - assert.Equal(t, testBundle.IsValueBundle(), true, "value bundle of source") - assert.Equal(t, len(testBundle.GetTransactionHashes()), len(transactions), "# of transactions of source") - assert.Equal(t, testBundle.GetTransactionHashes()[0], transactions[0], "transaction[0] of source") - assert.Equal(t, testBundle.GetTransactionHashes()[1], transactions[1], "transaction[1] of source") -} - -func TestBundle_SettersGettersMarshalUnmarshal(t *testing.T) { - bundleHash := trinary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - bundleEssenceHash := trinary.Trytes("B9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - transactions := []trinary.Trytes{ - bundleHash, - trinary.Trytes("C9999999999999999999999999999999999999999999999999999999999999999999999999999999F"), - } - - testBundle := New(bundleHash) - testBundle.SetTransactionHashes(transactions) - testBundle.SetBundleEssenceHash(bundleEssenceHash) - testBundle.SetValueBundle(true) - - var bundleUnmarshaled Bundle - err := bundleUnmarshaled.Unmarshal(testBundle.Marshal()) - if err != nil { - t.Error(err) - } - - assert.Equal(t, bundleUnmarshaled.GetHash(), testBundle.GetHash(), "hash of target") - assert.Equal(t, bundleUnmarshaled.GetBundleEssenceHash(), testBundle.GetBundleEssenceHash(), "bundle essence hash of target") - assert.Equal(t, bundleUnmarshaled.IsValueBundle(), true, "value bundle of target") - assert.Equal(t, len(bundleUnmarshaled.GetTransactionHashes()), len(transactions), "# of transactions of target") - assert.Equal(t, bundleUnmarshaled.GetTransactionHashes()[0], transactions[0], "transaction[0] of target") - assert.Equal(t, bundleUnmarshaled.GetTransactionHashes()[1], transactions[1], "transaction[1] of target") -} diff --git a/packages/model/bundle/constants.go b/packages/model/bundle/constants.go deleted file mode 100644 index 1575f582..00000000 --- a/packages/model/bundle/constants.go +++ /dev/null @@ -1,20 +0,0 @@ -package bundle - -const ( - MARSHALED_TRANSACTIONS_COUNT_START = 0 - MARSHALED_HASH_START = MARSHALED_TRANSACTIONS_COUNT_END - MARSHALED_BUNDLE_ESSENCE_HASH_START = MARSHALED_HASH_END - MARSHALED_FLAGS_START = MARSHALED_BUNDLE_ESSENCE_HASH_END - MARSHALED_APPROVERS_HASHES_START = MARSHALED_FLAGS_END - - MARSHALED_TRANSACTIONS_COUNT_END = MARSHALED_TRANSACTIONS_COUNT_START + MARSHALED_TRANSACTIONS_COUNT_SIZE - MARSHALED_HASH_END = MARSHALED_HASH_START + MARSHALED_TRANSACTION_HASH_SIZE - MARSHALED_BUNDLE_ESSENCE_HASH_END = MARSHALED_BUNDLE_ESSENCE_HASH_START + MARSHALED_BUNDLE_ESSENCE_HASH_SIZE - MARSHALED_FLAGS_END = MARSHALED_FLAGS_START + MARSHALED_FLAGS_SIZE - - MARSHALED_TRANSACTIONS_COUNT_SIZE = 8 - MARSHALED_TRANSACTION_HASH_SIZE = 81 - MARSHALED_BUNDLE_ESSENCE_HASH_SIZE = 81 - MARSHALED_FLAGS_SIZE = 1 - MARSHALED_MIN_SIZE = MARSHALED_TRANSACTIONS_COUNT_SIZE + MARSHALED_TRANSACTION_HASH_SIZE + MARSHALED_BUNDLE_ESSENCE_HASH_SIZE + MARSHALED_FLAGS_SIZE -) diff --git a/packages/model/error.go b/packages/model/error.go deleted file mode 100644 index b060d2d3..00000000 --- a/packages/model/error.go +++ /dev/null @@ -1,8 +0,0 @@ -package model - -import "errors" - -var ( - ErrUnmarshalFailed = errors.New("unmarshal failed") - ErrMarshalFailed = errors.New("marshal failed") -) diff --git a/packages/model/meta_transaction/constants.go b/packages/model/meta_transaction/constants.go deleted file mode 100644 index 399fd041..00000000 --- a/packages/model/meta_transaction/constants.go +++ /dev/null @@ -1,41 +0,0 @@ -package meta_transaction - -import ( - "github.com/iotaledger/iota.go/consts" - "github.com/iotaledger/iota.go/trinary" -) - -const ( - SHARD_MARKER_OFFSET = 0 - TRUNK_TRANSACTION_HASH_OFFSET = SHARD_MARKER_END - BRANCH_TRANSACTION_HASH_OFFSET = TRUNK_TRANSACTION_HASH_END - HEAD_OFFSET = BRANCH_TRANSACTION_HASH_END - TAIL_OFFSET = HEAD_END - TRANSACTION_TYPE_OFFSET = TAIL_END - DATA_OFFSET = TRANSACTION_TYPE_END - NONCE_OFFSET = DATA_END - - SHARD_MARKER_SIZE = 11 - TRUNK_TRANSACTION_HASH_SIZE = 243 - BRANCH_TRANSACTION_HASH_SIZE = 243 - HEAD_SIZE = 1 - TAIL_SIZE = 1 - TRANSACTION_TYPE_SIZE = 8 - DATA_SIZE = 6993 - NONCE_SIZE = consts.NonceTrinarySize - - SHARD_MARKER_END = SHARD_MARKER_OFFSET + SHARD_MARKER_SIZE - TRUNK_TRANSACTION_HASH_END = TRUNK_TRANSACTION_HASH_OFFSET + TRUNK_TRANSACTION_HASH_SIZE - BRANCH_TRANSACTION_HASH_END = BRANCH_TRANSACTION_HASH_OFFSET + BRANCH_TRANSACTION_HASH_SIZE - HEAD_END = HEAD_OFFSET + HEAD_SIZE - TAIL_END = TAIL_OFFSET + TAIL_SIZE - TRANSACTION_TYPE_END = TRANSACTION_TYPE_OFFSET + TRANSACTION_TYPE_SIZE - DATA_END = DATA_OFFSET + DATA_SIZE - NONCE_END = NONCE_OFFSET + NONCE_SIZE - - MARSHALED_TOTAL_SIZE = NONCE_END - - BRANCH_NULL_HASH = trinary.Trytes("999999999999999999999999999999999999999999999999999999999999999999999999999999999") - - MIN_WEIGHT_MAGNITUDE = 12 -) diff --git a/packages/model/meta_transaction/meta_transaction.go b/packages/model/meta_transaction/meta_transaction.go deleted file mode 100644 index 59c546ea..00000000 --- a/packages/model/meta_transaction/meta_transaction.go +++ /dev/null @@ -1,577 +0,0 @@ -package meta_transaction - -import ( - "errors" - "fmt" - "sync" - - "github.com/iotaledger/iota.go/consts" - "github.com/iotaledger/iota.go/curl" - "github.com/iotaledger/iota.go/pow" - "github.com/iotaledger/iota.go/trinary" -) - -var ( - ErrInvalidWeightMagnitude = errors.New("insufficient weight magnitude") -) - -type MetaTransaction struct { - hash *trinary.Trytes - weightMagnitude int - - shardMarker *trinary.Trytes - trunkTransactionHash *trinary.Trytes - branchTransactionHash *trinary.Trytes - head *bool - tail *bool - transactionType *trinary.Trytes - data trinary.Trits - modified bool - nonce *trinary.Trytes - - hasherMutex sync.RWMutex - hashMutex sync.RWMutex - shardMarkerMutex sync.RWMutex - trunkTransactionHashMutex sync.RWMutex - branchTransactionHashMutex sync.RWMutex - headMutex sync.RWMutex - tailMutex sync.RWMutex - transactionTypeMutex sync.RWMutex - dataMutex sync.RWMutex - bytesMutex sync.RWMutex - modifiedMutex sync.RWMutex - nonceMutex sync.RWMutex - - trits trinary.Trits - bytes []byte -} - -func New() *MetaTransaction { - return FromTrits(make(trinary.Trits, MARSHALED_TOTAL_SIZE)) -} - -func FromTrits(trits trinary.Trits) *MetaTransaction { - return &MetaTransaction{ - trits: trits, - } -} - -func FromBytes(bytes []byte) (result *MetaTransaction, err error) { - trits := trinary.MustBytesToTrits(bytes) - if len(trits) < MARSHALED_TOTAL_SIZE { - return nil, fmt.Errorf("invalid size %v", len(trits)) - } - result = FromTrits(trits[:MARSHALED_TOTAL_SIZE]) - result.bytes = bytes - - return -} - -func (this *MetaTransaction) BlockHasher() { - this.hasherMutex.RLock() -} - -func (this *MetaTransaction) UnblockHasher() { - this.hasherMutex.RUnlock() -} - -func (this *MetaTransaction) ReHash() { - this.hashMutex.Lock() - defer this.hashMutex.Unlock() - this.hash = nil - - this.bytesMutex.Lock() - defer this.bytesMutex.Unlock() - this.bytes = nil -} - -// retrieves the hash of the transaction -func (this *MetaTransaction) GetHash() (result trinary.Trytes) { - this.hashMutex.RLock() - if this.hash == nil { - this.hashMutex.RUnlock() - this.hashMutex.Lock() - defer this.hashMutex.Unlock() - if this.hash == nil { - this.hasherMutex.Lock() - this.computeHashDetails() - this.hasherMutex.Unlock() - } - } else { - defer this.hashMutex.RUnlock() - } - - result = *this.hash - - return -} - -// retrieves weight magnitude of the transaction (amount of pow invested) -func (this *MetaTransaction) GetWeightMagnitude() (result int) { - this.hashMutex.RLock() - if this.hash == nil { - this.hashMutex.RUnlock() - this.hashMutex.Lock() - defer this.hashMutex.Unlock() - if this.hash == nil { - this.hasherMutex.Lock() - this.computeHashDetails() - this.hasherMutex.Unlock() - } - } else { - defer this.hashMutex.RUnlock() - } - - result = this.weightMagnitude - - return -} - -// returns the trytes that are relevant for the transaction hash -func (this *MetaTransaction) getHashEssence() trinary.Trits { - txTrits := this.trits - - // very dirty hack, to get an iota.go compatible size - if len(txTrits) > consts.TransactionTrinarySize { - panic("transaction too large") - } - essenceTrits := make([]int8, consts.TransactionTrinarySize) - copy(essenceTrits[consts.TransactionTrinarySize-len(txTrits):], txTrits) - - return essenceTrits -} - -// hashes the transaction using curl (without locking - internal usage) -func (this *MetaTransaction) computeHashDetails() { - hashTrits, err := curl.HashTrits(this.getHashEssence()) - if err != nil { - panic(err) - } - hashTrytes := trinary.MustTritsToTrytes(hashTrits) - - this.hash = &hashTrytes - this.weightMagnitude = int(trinary.TrailingZeros(hashTrits)) -} - -// getter for the shard marker (supports concurrency) -func (this *MetaTransaction) GetShardMarker() (result trinary.Trytes) { - this.shardMarkerMutex.RLock() - if this.shardMarker == nil { - this.shardMarkerMutex.RUnlock() - this.shardMarkerMutex.Lock() - defer this.shardMarkerMutex.Unlock() - if this.shardMarker == nil { - shardMarker := trinary.MustTritsToTrytes(this.trits[SHARD_MARKER_OFFSET:SHARD_MARKER_END]) - - this.shardMarker = &shardMarker - } - } else { - defer this.shardMarkerMutex.RUnlock() - } - - result = *this.shardMarker - - return -} - -// setter for the shard marker (supports concurrency) -func (this *MetaTransaction) SetShardMarker(shardMarker trinary.Trytes) bool { - this.shardMarkerMutex.RLock() - if this.shardMarker == nil || *this.shardMarker != shardMarker { - this.shardMarkerMutex.RUnlock() - this.shardMarkerMutex.Lock() - defer this.shardMarkerMutex.Unlock() - if this.shardMarker == nil || *this.shardMarker != shardMarker { - this.shardMarker = &shardMarker - - this.hasherMutex.RLock() - copy(this.trits[SHARD_MARKER_OFFSET:SHARD_MARKER_END], trinary.MustTrytesToTrits(shardMarker)[:SHARD_MARKER_SIZE]) - this.hasherMutex.RUnlock() - - this.SetModified(true) - this.ReHash() - - return true - } - } else { - this.shardMarkerMutex.RUnlock() - } - - return false -} - -// getter for the bundleHash (supports concurrency) -func (this *MetaTransaction) GetTrunkTransactionHash() (result trinary.Trytes) { - this.trunkTransactionHashMutex.RLock() - if this.trunkTransactionHash == nil { - this.trunkTransactionHashMutex.RUnlock() - this.trunkTransactionHashMutex.Lock() - defer this.trunkTransactionHashMutex.Unlock() - if this.trunkTransactionHash == nil { - trunkTransactionHash := trinary.MustTritsToTrytes(this.trits[TRUNK_TRANSACTION_HASH_OFFSET:TRUNK_TRANSACTION_HASH_END]) - - this.trunkTransactionHash = &trunkTransactionHash - } - } else { - defer this.trunkTransactionHashMutex.RUnlock() - } - - result = *this.trunkTransactionHash - - return -} - -// setter for the trunkTransactionHash (supports concurrency) -func (this *MetaTransaction) SetTrunkTransactionHash(trunkTransactionHash trinary.Trytes) bool { - this.trunkTransactionHashMutex.RLock() - if this.trunkTransactionHash == nil || *this.trunkTransactionHash != trunkTransactionHash { - this.trunkTransactionHashMutex.RUnlock() - this.trunkTransactionHashMutex.Lock() - defer this.trunkTransactionHashMutex.Unlock() - if this.trunkTransactionHash == nil || *this.trunkTransactionHash != trunkTransactionHash { - this.trunkTransactionHash = &trunkTransactionHash - - this.hasherMutex.RLock() - copy(this.trits[TRUNK_TRANSACTION_HASH_OFFSET:TRUNK_TRANSACTION_HASH_END], trinary.MustTrytesToTrits(trunkTransactionHash)[:TRUNK_TRANSACTION_HASH_SIZE]) - this.hasherMutex.RUnlock() - - this.SetModified(true) - this.ReHash() - - return true - } - } else { - this.trunkTransactionHashMutex.RUnlock() - } - - return false -} - -// getter for the bundleHash (supports concurrency) -func (this *MetaTransaction) GetBranchTransactionHash() (result trinary.Trytes) { - this.branchTransactionHashMutex.RLock() - if this.branchTransactionHash == nil { - this.branchTransactionHashMutex.RUnlock() - this.branchTransactionHashMutex.Lock() - defer this.branchTransactionHashMutex.Unlock() - if this.branchTransactionHash == nil { - branchTransactionHash := trinary.MustTritsToTrytes(this.trits[BRANCH_TRANSACTION_HASH_OFFSET:BRANCH_TRANSACTION_HASH_END]) - - this.branchTransactionHash = &branchTransactionHash - } - } else { - defer this.branchTransactionHashMutex.RUnlock() - } - - result = *this.branchTransactionHash - - return -} - -// setter for the trunkTransactionHash (supports concurrency) -func (this *MetaTransaction) SetBranchTransactionHash(branchTransactionHash trinary.Trytes) bool { - this.branchTransactionHashMutex.RLock() - if this.branchTransactionHash == nil || *this.branchTransactionHash != branchTransactionHash { - this.branchTransactionHashMutex.RUnlock() - this.branchTransactionHashMutex.Lock() - defer this.branchTransactionHashMutex.Unlock() - if this.branchTransactionHash == nil || *this.branchTransactionHash != branchTransactionHash { - this.branchTransactionHash = &branchTransactionHash - - this.hasherMutex.RLock() - copy(this.trits[BRANCH_TRANSACTION_HASH_OFFSET:BRANCH_TRANSACTION_HASH_END], trinary.MustTrytesToTrits(branchTransactionHash)[:BRANCH_TRANSACTION_HASH_SIZE]) - this.hasherMutex.RUnlock() - - this.SetModified(true) - this.ReHash() - - return true - } - } else { - this.branchTransactionHashMutex.RUnlock() - } - - return false -} - -// getter for the head flag (supports concurrency) -func (this *MetaTransaction) IsHead() (result bool) { - this.headMutex.RLock() - if this.head == nil { - this.headMutex.RUnlock() - this.headMutex.Lock() - defer this.headMutex.Unlock() - if this.head == nil { - head := this.trits[HEAD_OFFSET] == 1 - - this.head = &head - } - } else { - defer this.headMutex.RUnlock() - } - - result = *this.head - - return -} - -// setter for the head flag (supports concurrency) -func (this *MetaTransaction) SetHead(head bool) bool { - this.headMutex.RLock() - if this.head == nil || *this.head != head { - this.headMutex.RUnlock() - this.headMutex.Lock() - defer this.headMutex.Unlock() - if this.head == nil || *this.head != head { - this.head = &head - - this.hasherMutex.RLock() - if head { - this.trits[HEAD_OFFSET] = 1 - } else { - this.trits[HEAD_OFFSET] = 0 - } - this.hasherMutex.RUnlock() - - this.SetModified(true) - this.ReHash() - - return true - } - } else { - this.headMutex.RUnlock() - } - - return false -} - -// getter for the tail flag (supports concurrency) -func (this *MetaTransaction) IsTail() (result bool) { - this.tailMutex.RLock() - if this.tail == nil { - this.tailMutex.RUnlock() - this.tailMutex.Lock() - defer this.tailMutex.Unlock() - if this.tail == nil { - tail := this.trits[TAIL_OFFSET] == 1 - - this.tail = &tail - } - } else { - defer this.tailMutex.RUnlock() - } - - result = *this.tail - - return -} - -// setter for the tail flag (supports concurrency) -func (this *MetaTransaction) SetTail(tail bool) bool { - this.tailMutex.RLock() - if this.tail == nil || *this.tail != tail { - this.tailMutex.RUnlock() - this.tailMutex.Lock() - defer this.tailMutex.Unlock() - if this.tail == nil || *this.tail != tail { - this.tail = &tail - - this.hasherMutex.RLock() - if tail { - this.trits[TAIL_OFFSET] = 1 - } else { - this.trits[TAIL_OFFSET] = 0 - } - this.hasherMutex.RUnlock() - - this.SetModified(true) - this.ReHash() - - return true - } - } else { - this.tailMutex.RUnlock() - } - - return false -} - -// getter for the transaction type (supports concurrency) -func (this *MetaTransaction) GetTransactionType() (result trinary.Trytes) { - this.transactionTypeMutex.RLock() - if this.transactionType == nil { - this.transactionTypeMutex.RUnlock() - this.transactionTypeMutex.Lock() - defer this.transactionTypeMutex.Unlock() - if this.transactionType == nil { - transactionType := trinary.MustTritsToTrytes(this.trits[TRANSACTION_TYPE_OFFSET:TRANSACTION_TYPE_END]) - - this.transactionType = &transactionType - } - } else { - defer this.transactionTypeMutex.RUnlock() - } - - result = *this.transactionType - - return -} - -// setter for the transaction type (supports concurrency) -func (this *MetaTransaction) SetTransactionType(transactionType trinary.Trytes) bool { - this.transactionTypeMutex.RLock() - if this.transactionType == nil || *this.transactionType != transactionType { - this.transactionTypeMutex.RUnlock() - this.transactionTypeMutex.Lock() - defer this.transactionTypeMutex.Unlock() - if this.transactionType == nil || *this.transactionType != transactionType { - this.transactionType = &transactionType - - this.hasherMutex.RLock() - copy(this.trits[TRANSACTION_TYPE_OFFSET:TRANSACTION_TYPE_END], trinary.MustTrytesToTrits(transactionType)[:TRANSACTION_TYPE_SIZE]) - this.hasherMutex.RUnlock() - - this.SetModified(true) - this.ReHash() - - return true - } - } else { - this.transactionTypeMutex.RUnlock() - } - - return false -} - -// getter for the data slice (supports concurrency) -func (this *MetaTransaction) GetData() (result trinary.Trits) { - this.dataMutex.RLock() - if this.data == nil { - this.dataMutex.RUnlock() - this.dataMutex.Lock() - defer this.dataMutex.Unlock() - if this.data == nil { - this.data = this.trits[DATA_OFFSET:DATA_END] - } - } else { - defer this.dataMutex.RUnlock() - } - - result = this.data - - return -} - -func (this *MetaTransaction) GetTrits() (result trinary.Trits) { - result = make(trinary.Trits, len(this.trits)) - - this.hasherMutex.Lock() - copy(result, this.trits) - this.hasherMutex.Unlock() - - return -} - -func (this *MetaTransaction) GetBytes() (result []byte) { - this.bytesMutex.RLock() - if this.bytes == nil { - this.bytesMutex.RUnlock() - this.bytesMutex.Lock() - defer this.bytesMutex.Unlock() - - this.hasherMutex.Lock() - this.bytes = trinary.MustTritsToBytes(this.trits) - this.hasherMutex.Unlock() - } else { - this.bytesMutex.RUnlock() - } - - result = make([]byte, len(this.bytes)) - copy(result, this.bytes) - - return -} - -func (this *MetaTransaction) GetNonce() trinary.Trytes { - this.nonceMutex.RLock() - if this.nonce == nil { - this.nonceMutex.RUnlock() - this.nonceMutex.Lock() - defer this.nonceMutex.Unlock() - if this.nonce == nil { - nonce := trinary.MustTritsToTrytes(this.trits[NONCE_OFFSET:NONCE_END]) - - this.nonce = &nonce - } - } else { - defer this.nonceMutex.RUnlock() - } - - return *this.nonce -} - -func (this *MetaTransaction) SetNonce(nonce trinary.Trytes) bool { - this.nonceMutex.RLock() - if this.nonce == nil || *this.nonce != nonce { - this.nonceMutex.RUnlock() - this.nonceMutex.Lock() - defer this.nonceMutex.Unlock() - if this.nonce == nil || *this.nonce != nonce { - this.nonce = &nonce - - this.hasherMutex.RLock() - copy(this.trits[NONCE_OFFSET:NONCE_END], trinary.MustTrytesToTrits(nonce)[:NONCE_SIZE]) - this.hasherMutex.RUnlock() - - this.SetModified(true) - this.ReHash() - - return true - } - } else { - this.nonceMutex.RUnlock() - } - - return false -} - -// returns true if the transaction contains unsaved changes (supports concurrency) -func (this *MetaTransaction) GetModified() bool { - this.modifiedMutex.RLock() - defer this.modifiedMutex.RUnlock() - - return this.modified -} - -// sets the modified flag which controls if a transaction is going to be saved (supports concurrency) -func (this *MetaTransaction) SetModified(modified bool) { - this.modifiedMutex.Lock() - defer this.modifiedMutex.Unlock() - - this.modified = modified -} - -func (this *MetaTransaction) DoProofOfWork(mwm int) error { - this.hasherMutex.Lock() - powTrytes := trinary.MustTritsToTrytes(this.getHashEssence()) - _, pow := pow.GetFastestProofOfWorkImpl() - nonce, err := pow(powTrytes, mwm) - this.hasherMutex.Unlock() - - if err != nil { - return fmt.Errorf("PoW failed: %w", err) - } - this.SetNonce(nonce) - - return nil -} - -func (this *MetaTransaction) Validate() error { - // check that the weight magnitude is valid - weightMagnitude := this.GetWeightMagnitude() - if weightMagnitude < MIN_WEIGHT_MAGNITUDE { - return fmt.Errorf("%w: got=%d, want=%d", ErrInvalidWeightMagnitude, weightMagnitude, MIN_WEIGHT_MAGNITUDE) - } - - return nil -} diff --git a/packages/model/meta_transaction/meta_transaction_test.go b/packages/model/meta_transaction/meta_transaction_test.go deleted file mode 100644 index 7a349f2d..00000000 --- a/packages/model/meta_transaction/meta_transaction_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package meta_transaction - -import ( - "sync" - "testing" - - "github.com/iotaledger/iota.go/trinary" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -const ( - shardMarker = trinary.Trytes("NPHTQORL9XKA") - trunkTransactionHash = trinary.Trytes("99999999999999999999999999999999999999999999999999999999999999999999999999999999A") - branchTransactionHash = trinary.Trytes("99999999999999999999999999999999999999999999999999999999999999999999999999999999B") - head = true - tail = true - transactionType = trinary.Trytes("9999999999999999999999") -) - -func newTestTransaction() *MetaTransaction { - tx := New() - tx.SetShardMarker(shardMarker) - tx.SetTrunkTransactionHash(trunkTransactionHash) - tx.SetBranchTransactionHash(branchTransactionHash) - tx.SetHead(head) - tx.SetTail(tail) - tx.SetTransactionType(transactionType) - - return tx -} - -func TestDoPow(t *testing.T) { - tx := newTestTransaction() - require.NoError(t, tx.DoProofOfWork(10)) - - assert.GreaterOrEqual(t, tx.GetWeightMagnitude(), 10) -} - -func TestMetaTransaction_SettersGetters(t *testing.T) { - tx := newTestTransaction() - - assert.Equal(t, tx.GetWeightMagnitude(), 0) - assert.Equal(t, tx.GetShardMarker(), shardMarker) - assert.Equal(t, tx.GetTrunkTransactionHash(), trunkTransactionHash) - assert.Equal(t, tx.GetBranchTransactionHash(), branchTransactionHash) - assert.Equal(t, tx.IsHead(), head) - assert.Equal(t, tx.IsTail(), tail) - assert.Equal(t, tx.GetTransactionType(), transactionType) - metaTx, err := FromBytes(tx.GetBytes()) - require.NoError(t, err) - assert.Equal(t, tx.GetHash(), metaTx.GetHash()) - - assert.EqualValues(t, "KKDVHBENVLQUNO9WOWWEJPBBHUSYRSRKIMZWCFCDB9RYZKYWLAYWRIBRQETBFKE9TIVWQPCKFWAMCLCAV", tx.GetHash()) -} - -func BenchmarkMetaTransaction_GetHash(b *testing.B) { - var waitGroup sync.WaitGroup - - for i := 0; i < b.N; i++ { - waitGroup.Add(1) - - go func() { - New().GetHash() - - waitGroup.Done() - }() - } - - waitGroup.Wait() -} diff --git a/packages/model/transactionmetadata/const.go b/packages/model/transactionmetadata/const.go deleted file mode 100644 index 100a51dd..00000000 --- a/packages/model/transactionmetadata/const.go +++ /dev/null @@ -1,21 +0,0 @@ -package transactionmetadata - -// region constants and variables ////////////////////////////////////////////////////////////////////////////////////// - -const ( - MARSHALED_HASH_START = 0 - MARSHALED_RECEIVED_TIME_START = MARSHALED_HASH_END - MARSHALED_FLAGS_START = MARSHALED_RECEIVED_TIME_END - - MARSHALED_HASH_END = MARSHALED_HASH_START + MARSHALED_HASH_SIZE - MARSHALED_RECEIVED_TIME_END = MARSHALED_RECEIVED_TIME_START + MARSHALED_RECEIVED_TIME_SIZE - MARSHALED_FLAGS_END = MARSHALED_FLAGS_START + MARSHALED_FLAGS_SIZE - - MARSHALED_HASH_SIZE = 81 - MARSHALED_RECEIVED_TIME_SIZE = 15 - MARSHALED_FLAGS_SIZE = 1 - - MARSHALED_TOTAL_SIZE = MARSHALED_FLAGS_END -) - -// endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/packages/model/transactionmetadata/transactionmetadata.go b/packages/model/transactionmetadata/transactionmetadata.go deleted file mode 100644 index 66a27966..00000000 --- a/packages/model/transactionmetadata/transactionmetadata.go +++ /dev/null @@ -1,277 +0,0 @@ -package transactionmetadata - -import ( - "fmt" - "sync" - "time" - - "github.com/iotaledger/goshimmer/packages/model" - "github.com/iotaledger/hive.go/bitmask" - "github.com/iotaledger/hive.go/typeutils" - "github.com/iotaledger/iota.go/trinary" -) - -// region type definition and constructor ////////////////////////////////////////////////////////////////////////////// - -type TransactionMetadata struct { - hash trinary.Trytes - hashMutex sync.RWMutex - bundleHeadHash trinary.Trytes - bundleHeadHashMutex sync.RWMutex - receivedTime time.Time - receivedTimeMutex sync.RWMutex - solid bool - solidMutex sync.RWMutex - liked bool - likedMutex sync.RWMutex - finalized bool - finalizedMutex sync.RWMutex - modified bool - modifiedMutex sync.RWMutex -} - -func New(hash trinary.Trytes) *TransactionMetadata { - return &TransactionMetadata{ - hash: hash, - receivedTime: time.Now(), - solid: false, - liked: false, - finalized: false, - modified: true, - } -} - -// endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// region getters and setters ////////////////////////////////////////////////////////////////////////////////////////// - -func (metadata *TransactionMetadata) GetHash() trinary.Trytes { - metadata.hashMutex.RLock() - defer metadata.hashMutex.RUnlock() - - return metadata.hash -} - -func (metadata *TransactionMetadata) SetHash(hash trinary.Trytes) { - metadata.hashMutex.RLock() - if metadata.hash != hash { - metadata.hashMutex.RUnlock() - metadata.hashMutex.Lock() - defer metadata.hashMutex.Unlock() - if metadata.hash != hash { - metadata.hash = hash - - metadata.SetModified(true) - } - } else { - metadata.hashMutex.RUnlock() - } -} - -func (metadata *TransactionMetadata) GetBundleHeadHash() trinary.Trytes { - metadata.bundleHeadHashMutex.RLock() - defer metadata.bundleHeadHashMutex.RUnlock() - - return metadata.bundleHeadHash -} - -func (metadata *TransactionMetadata) SetBundleHeadHash(bundleTailHash trinary.Trytes) { - metadata.bundleHeadHashMutex.RLock() - if metadata.bundleHeadHash != bundleTailHash { - metadata.bundleHeadHashMutex.RUnlock() - metadata.bundleHeadHashMutex.Lock() - defer metadata.bundleHeadHashMutex.Unlock() - if metadata.bundleHeadHash != bundleTailHash { - metadata.bundleHeadHash = bundleTailHash - - metadata.SetModified(true) - } - } else { - metadata.bundleHeadHashMutex.RUnlock() - } -} - -func (metadata *TransactionMetadata) GetReceivedTime() time.Time { - metadata.receivedTimeMutex.RLock() - defer metadata.receivedTimeMutex.RUnlock() - - return metadata.receivedTime -} - -func (metadata *TransactionMetadata) SetReceivedTime(receivedTime time.Time) { - metadata.receivedTimeMutex.RLock() - if metadata.receivedTime != receivedTime { - metadata.receivedTimeMutex.RUnlock() - metadata.receivedTimeMutex.Lock() - defer metadata.receivedTimeMutex.Unlock() - if metadata.receivedTime != receivedTime { - metadata.receivedTime = receivedTime - - metadata.SetModified(true) - } - } else { - metadata.receivedTimeMutex.RUnlock() - } -} - -func (metadata *TransactionMetadata) GetSolid() bool { - metadata.solidMutex.RLock() - defer metadata.solidMutex.RUnlock() - - return metadata.solid -} - -func (metadata *TransactionMetadata) SetSolid(solid bool) bool { - metadata.solidMutex.RLock() - if metadata.solid != solid { - metadata.solidMutex.RUnlock() - metadata.solidMutex.Lock() - defer metadata.solidMutex.Unlock() - if metadata.solid != solid { - metadata.solid = solid - - metadata.SetModified(true) - - return true - } - } else { - metadata.solidMutex.RUnlock() - } - - return false -} - -func (metadata *TransactionMetadata) GetLiked() bool { - metadata.likedMutex.RLock() - defer metadata.likedMutex.RUnlock() - - return metadata.liked -} - -func (metadata *TransactionMetadata) SetLiked(liked bool) { - metadata.likedMutex.RLock() - if metadata.liked != liked { - metadata.likedMutex.RUnlock() - metadata.likedMutex.Lock() - defer metadata.likedMutex.Unlock() - if metadata.liked != liked { - metadata.liked = liked - - metadata.SetModified(true) - } - } else { - metadata.likedMutex.RUnlock() - } -} - -func (metadata *TransactionMetadata) GetFinalized() bool { - metadata.finalizedMutex.RLock() - defer metadata.finalizedMutex.RUnlock() - - return metadata.finalized -} - -func (metadata *TransactionMetadata) SetFinalized(finalized bool) { - metadata.finalizedMutex.RLock() - if metadata.finalized != finalized { - metadata.finalizedMutex.RUnlock() - metadata.finalizedMutex.Lock() - defer metadata.finalizedMutex.Unlock() - if metadata.finalized != finalized { - metadata.finalized = finalized - - metadata.SetModified(true) - } - } else { - metadata.finalizedMutex.RUnlock() - } -} - -// returns true if the transaction contains unsaved changes (supports concurrency) -func (metadata *TransactionMetadata) GetModified() bool { - metadata.modifiedMutex.RLock() - defer metadata.modifiedMutex.RUnlock() - - return metadata.modified -} - -// sets the modified flag which controls if a transaction is going to be saved (supports concurrency) -func (metadata *TransactionMetadata) SetModified(modified bool) { - metadata.modifiedMutex.Lock() - defer metadata.modifiedMutex.Unlock() - - metadata.modified = modified -} - -// endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////// - -// region marshaling functions ///////////////////////////////////////////////////////////////////////////////////////// - -func (metadata *TransactionMetadata) Marshal() ([]byte, error) { - marshaledMetadata := make([]byte, MARSHALED_TOTAL_SIZE) - - metadata.receivedTimeMutex.RLock() - defer metadata.receivedTimeMutex.RUnlock() - metadata.solidMutex.RLock() - defer metadata.solidMutex.RUnlock() - metadata.likedMutex.RLock() - defer metadata.likedMutex.RUnlock() - metadata.finalizedMutex.RLock() - defer metadata.finalizedMutex.RUnlock() - - copy(marshaledMetadata[MARSHALED_HASH_START:MARSHALED_HASH_END], typeutils.StringToBytes(metadata.hash)) - - marshaledReceivedTime, err := metadata.receivedTime.MarshalBinary() - if err != nil { - return nil, fmt.Errorf("%w: failed to marshal received time: %s", model.ErrMarshalFailed, err.Error()) - } - copy(marshaledMetadata[MARSHALED_RECEIVED_TIME_START:MARSHALED_RECEIVED_TIME_END], marshaledReceivedTime) - - var booleanFlags bitmask.BitMask - if metadata.solid { - booleanFlags = booleanFlags.SetFlag(0) - } - if metadata.liked { - booleanFlags = booleanFlags.SetFlag(1) - } - if metadata.finalized { - booleanFlags = booleanFlags.SetFlag(2) - } - marshaledMetadata[MARSHALED_FLAGS_START] = byte(booleanFlags) - - return marshaledMetadata, nil -} - -func (metadata *TransactionMetadata) Unmarshal(data []byte) error { - metadata.hashMutex.Lock() - defer metadata.hashMutex.Unlock() - metadata.receivedTimeMutex.Lock() - defer metadata.receivedTimeMutex.Unlock() - metadata.solidMutex.Lock() - defer metadata.solidMutex.Unlock() - metadata.likedMutex.Lock() - defer metadata.likedMutex.Unlock() - metadata.finalizedMutex.Lock() - defer metadata.finalizedMutex.Unlock() - - metadata.hash = typeutils.BytesToString(data[MARSHALED_HASH_START:MARSHALED_HASH_END]) - - if err := metadata.receivedTime.UnmarshalBinary(data[MARSHALED_RECEIVED_TIME_START:MARSHALED_RECEIVED_TIME_END]); err != nil { - return fmt.Errorf("%w: could not unmarshal the received time: %s", model.ErrUnmarshalFailed, err.Error()) - } - - booleanFlags := bitmask.BitMask(data[MARSHALED_FLAGS_START]) - if booleanFlags.HasFlag(0) { - metadata.solid = true - } - if booleanFlags.HasFlag(1) { - metadata.liked = true - } - if booleanFlags.HasFlag(2) { - metadata.finalized = true - } - - return nil -} - -// endregion /////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/packages/model/value_transaction/constants.go b/packages/model/value_transaction/constants.go deleted file mode 100644 index 06a4c749..00000000 --- a/packages/model/value_transaction/constants.go +++ /dev/null @@ -1,31 +0,0 @@ -package value_transaction - -import ( - "strings" - - "github.com/iotaledger/iota.go/trinary" -) - -const ( - ADDRESS_OFFSET = 0 - VALUE_OFFSET = ADDRESS_END - TIMESTAMP_OFFSET = VALUE_END - SIGNATURE_MESSAGE_FRAGMENT_OFFSET = TIMESTAMP_END - - ADDRESS_SIZE = 243 - VALUE_SIZE = 81 - TIMESTAMP_SIZE = 27 - SIGNATURE_MESSAGE_FRAGMENT_SIZE = 6561 - BUNDLE_ESSENCE_SIZE = ADDRESS_SIZE + VALUE_SIZE + SIGNATURE_MESSAGE_FRAGMENT_SIZE - - ADDRESS_END = ADDRESS_OFFSET + ADDRESS_SIZE - VALUE_END = VALUE_OFFSET + VALUE_SIZE - TIMESTAMP_END = TIMESTAMP_OFFSET + TIMESTAMP_SIZE - SIGNATURE_MESSAGE_FRAGMENT_END = SIGNATURE_MESSAGE_FRAGMENT_OFFSET + SIGNATURE_MESSAGE_FRAGMENT_SIZE - - TOTAL_SIZE = SIGNATURE_MESSAGE_FRAGMENT_END -) - -var ( - EMPTY_SIGNATURE = trinary.Trytes(strings.Repeat("9", SIGNATURE_MESSAGE_FRAGMENT_SIZE/3)) -) diff --git a/packages/model/value_transaction/value_transaction.go b/packages/model/value_transaction/value_transaction.go deleted file mode 100644 index 393e6560..00000000 --- a/packages/model/value_transaction/value_transaction.go +++ /dev/null @@ -1,257 +0,0 @@ -package value_transaction - -import ( - "sync" - - "github.com/iotaledger/goshimmer/packages/model/meta_transaction" - "github.com/iotaledger/iota.go/trinary" -) - -type ValueTransaction struct { - *meta_transaction.MetaTransaction - - address *trinary.Trytes - addressMutex sync.RWMutex - value *int64 - valueMutex sync.RWMutex - timestamp *uint - timestampMutex sync.RWMutex - signatureMessageFragment *trinary.Trytes - signatureMessageFragmentMutex sync.RWMutex - - trits trinary.Trits -} - -func New() (result *ValueTransaction) { - result = &ValueTransaction{ - MetaTransaction: meta_transaction.New(), - } - - result.trits = result.MetaTransaction.GetData() - - return -} - -func FromMetaTransaction(metaTransaction *meta_transaction.MetaTransaction) *ValueTransaction { - return &ValueTransaction{ - MetaTransaction: metaTransaction, - trits: metaTransaction.GetData(), - } -} - -func FromBytes(bytes []byte) (result *ValueTransaction) { - trits := trinary.MustBytesToTrits(bytes) - result = &ValueTransaction{ - MetaTransaction: meta_transaction.FromTrits(trits[:meta_transaction.MARSHALED_TOTAL_SIZE]), - } - - result.trits = result.MetaTransaction.GetData() - - return -} - -// getter for the address (supports concurrency) -func (this *ValueTransaction) GetAddress() (result trinary.Trytes) { - this.addressMutex.RLock() - if this.address == nil { - this.addressMutex.RUnlock() - this.addressMutex.Lock() - defer this.addressMutex.Unlock() - if this.address == nil { - address := trinary.MustTritsToTrytes(this.trits[ADDRESS_OFFSET:ADDRESS_END]) - - this.address = &address - } - } else { - defer this.addressMutex.RUnlock() - } - - result = *this.address - - return -} - -// setter for the address (supports concurrency) -func (this *ValueTransaction) SetAddress(address trinary.Trytes) bool { - this.addressMutex.RLock() - if this.address == nil || *this.address != address { - this.addressMutex.RUnlock() - this.addressMutex.Lock() - defer this.addressMutex.Unlock() - if this.address == nil || *this.address != address { - this.address = &address - - this.BlockHasher() - copy(this.trits[ADDRESS_OFFSET:ADDRESS_END], trinary.MustTrytesToTrits(address)[:ADDRESS_SIZE]) - this.UnblockHasher() - - this.SetModified(true) - this.ReHash() - - return true - } - } else { - this.addressMutex.RUnlock() - } - - return false -} - -// getter for the value (supports concurrency) -func (this *ValueTransaction) GetValue() (result int64) { - this.valueMutex.RLock() - if this.value == nil { - this.valueMutex.RUnlock() - this.valueMutex.Lock() - defer this.valueMutex.Unlock() - if this.value == nil { - value := trinary.TritsToInt(this.trits[VALUE_OFFSET:VALUE_END]) - - this.value = &value - } - } else { - defer this.valueMutex.RUnlock() - } - - result = *this.value - - return -} - -// setter for the value (supports concurrency) -func (this *ValueTransaction) SetValue(value int64) bool { - this.valueMutex.RLock() - if this.value == nil || *this.value != value { - this.valueMutex.RUnlock() - this.valueMutex.Lock() - defer this.valueMutex.Unlock() - if this.value == nil || *this.value != value { - this.value = &value - - this.BlockHasher() - copy(this.trits[VALUE_OFFSET:], trinary.IntToTrits(value)) - this.UnblockHasher() - - this.SetModified(true) - this.ReHash() - - return true - } - } else { - this.valueMutex.RUnlock() - } - - return false -} - -// getter for the timestamp (supports concurrency) -func (this *ValueTransaction) GetTimestamp() (result uint) { - this.timestampMutex.RLock() - if this.timestamp == nil { - this.timestampMutex.RUnlock() - this.timestampMutex.Lock() - defer this.timestampMutex.Unlock() - if this.timestamp == nil { - timestamp := uint(trinary.TritsToInt(this.trits[TIMESTAMP_OFFSET:TIMESTAMP_END])) - - this.timestamp = ×tamp - } - } else { - defer this.timestampMutex.RUnlock() - } - - result = *this.timestamp - - return -} - -// setter for the timestamp (supports concurrency) -func (this *ValueTransaction) SetTimestamp(timestamp uint) bool { - this.timestampMutex.RLock() - if this.timestamp == nil || *this.timestamp != timestamp { - this.timestampMutex.RUnlock() - this.timestampMutex.Lock() - defer this.timestampMutex.Unlock() - if this.timestamp == nil || *this.timestamp != timestamp { - this.timestamp = ×tamp - - this.BlockHasher() - copy(this.trits[TIMESTAMP_OFFSET:TIMESTAMP_END], trinary.MustPadTrits(trinary.IntToTrits(int64(timestamp)), TIMESTAMP_SIZE)[:TIMESTAMP_SIZE]) - this.UnblockHasher() - - this.SetModified(true) - this.ReHash() - - return true - } - } else { - this.timestampMutex.RUnlock() - } - - return false -} - -func (this *ValueTransaction) GetBundleEssence(includeSignatureMessageFragment bool) (result trinary.Trits) { - this.signatureMessageFragmentMutex.RLock() - - result = make(trinary.Trits, BUNDLE_ESSENCE_SIZE) - - this.addressMutex.RLock() - copy(result[0:], this.trits[ADDRESS_OFFSET:VALUE_END]) - this.addressMutex.RUnlock() - - if includeSignatureMessageFragment { - copy(result[VALUE_END:], this.trits[SIGNATURE_MESSAGE_FRAGMENT_OFFSET:SIGNATURE_MESSAGE_FRAGMENT_END]) - } - - this.signatureMessageFragmentMutex.RUnlock() - - return -} - -// getter for the signatureMessageFragmetn (supports concurrency) -func (this *ValueTransaction) GetSignatureMessageFragment() (result trinary.Trytes) { - this.signatureMessageFragmentMutex.RLock() - if this.signatureMessageFragment == nil { - this.signatureMessageFragmentMutex.RUnlock() - this.signatureMessageFragmentMutex.Lock() - defer this.signatureMessageFragmentMutex.Unlock() - if this.signatureMessageFragment == nil { - signatureMessageFragment := trinary.MustTritsToTrytes(this.trits[SIGNATURE_MESSAGE_FRAGMENT_OFFSET:SIGNATURE_MESSAGE_FRAGMENT_END]) - - this.signatureMessageFragment = &signatureMessageFragment - } - } else { - defer this.signatureMessageFragmentMutex.RUnlock() - } - - result = *this.signatureMessageFragment - - return -} - -// setter for the nonce (supports concurrency) -func (this *ValueTransaction) SetSignatureMessageFragment(signatureMessageFragment trinary.Trytes) bool { - this.signatureMessageFragmentMutex.RLock() - if this.signatureMessageFragment == nil || *this.signatureMessageFragment != signatureMessageFragment { - this.signatureMessageFragmentMutex.RUnlock() - this.signatureMessageFragmentMutex.Lock() - defer this.signatureMessageFragmentMutex.Unlock() - if this.signatureMessageFragment == nil || *this.signatureMessageFragment != signatureMessageFragment { - this.signatureMessageFragment = &signatureMessageFragment - - this.BlockHasher() - copy(this.trits[SIGNATURE_MESSAGE_FRAGMENT_OFFSET:SIGNATURE_MESSAGE_FRAGMENT_END], trinary.MustTrytesToTrits(signatureMessageFragment)[:SIGNATURE_MESSAGE_FRAGMENT_SIZE]) - this.UnblockHasher() - - this.SetModified(true) - this.ReHash() - - return true - } - } else { - this.signatureMessageFragmentMutex.RUnlock() - } - - return false -} diff --git a/packages/model/value_transaction/value_transaction_test.go b/packages/model/value_transaction/value_transaction_test.go deleted file mode 100644 index c1f732d6..00000000 --- a/packages/model/value_transaction/value_transaction_test.go +++ /dev/null @@ -1,25 +0,0 @@ -package value_transaction - -import ( - "fmt" - "testing" - - "github.com/iotaledger/iota.go/trinary" - "github.com/magiconair/properties/assert" -) - -func TestValueTransaction_SettersGetters(t *testing.T) { - address := trinary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") - - transaction := New() - transaction.SetAddress(address) - - transactionCopy := FromMetaTransaction(transaction.MetaTransaction) - fmt.Println(transactionCopy.GetAddress()) - - assert.Equal(t, transaction.GetAddress(), address) - //assert.Equal(t, transaction.GetHash(), FromBytes(transaction.GetBytes()).GetHash()) - - fmt.Println(transaction.GetHash()) - fmt.Println(transaction.GetAddress()) -} -- GitLab