diff --git a/packages/curl/batch_hasher.go b/packages/curl/batch_hasher.go index c139d50f9923a40d7ca3aa6507fd3a447809133d..af38a90bcad20cd951c464384adea3e5e0c574fc 100644 --- a/packages/curl/batch_hasher.go +++ b/packages/curl/batch_hasher.go @@ -77,7 +77,7 @@ func (this *BatchHasher) processHashes(collectedHashRequests []HashRequest) { for _, hashRequest := range collectedHashRequests { multiplexer.Add(hashRequest.input) } - bcTrinary, err := multiplexer.Extract() + bcTrits, err := multiplexer.Extract() if err != nil { fmt.Println(err) } @@ -85,7 +85,7 @@ func (this *BatchHasher) processHashes(collectedHashRequests []HashRequest) { // calculate the hash bctCurl := NewBCTCurl(this.hashLength, this.rounds) bctCurl.Reset() - bctCurl.Absorb(bcTrinary) + bctCurl.Absorb(bcTrits) // extract the results from the demultiplexer demux := ternary.NewBCTernaryDemultiplexer(bctCurl.Squeeze(243)) @@ -105,9 +105,9 @@ func (this *BatchHasher) processHashes(collectedHashRequests []HashRequest) { } } -func (this *BatchHasher) Hash(trinary ternary.Trits) chan ternary.Trits { +func (this *BatchHasher) Hash(trits ternary.Trits) chan ternary.Trits { hashRequest := HashRequest{ - input: trinary, + input: trits, output: make(chan ternary.Trits, 1), } diff --git a/packages/curl/bct_curl.go b/packages/curl/bct_curl.go index 90045cef861639ea202d3f1272ed2d3b69919513..7933d3bcbe63db9a856719a8d8f52693bbae1d0c 100644 --- a/packages/curl/bct_curl.go +++ b/packages/curl/bct_curl.go @@ -10,7 +10,7 @@ type BCTCurl struct { hashLength int numberOfRounds int stateLength int - state ternary.BCTrinary + state ternary.BCTrits cTransform func() } @@ -19,7 +19,7 @@ func NewBCTCurl(hashLength int, numberOfRounds int) *BCTCurl { hashLength: hashLength, numberOfRounds: numberOfRounds, stateLength: ternary.NUMBER_OF_TRITS_IN_A_TRYTE * hashLength, - state: ternary.BCTrinary{ + state: ternary.BCTrits{ Lo: make([]uint, ternary.NUMBER_OF_TRITS_IN_A_TRYTE*hashLength), Hi: make([]uint, ternary.NUMBER_OF_TRITS_IN_A_TRYTE*hashLength), }, @@ -64,7 +64,7 @@ func (this *BCTCurl) Transform() { } } -func (this *BCTCurl) Absorb(bcTrits ternary.BCTrinary) { +func (this *BCTCurl) Absorb(bcTrits ternary.BCTrits) { length := len(bcTrits.Lo) offset := 0 @@ -89,8 +89,8 @@ func (this *BCTCurl) Absorb(bcTrits ternary.BCTrinary) { } } -func (this *BCTCurl) Squeeze(tritCount int) ternary.BCTrinary { - result := ternary.BCTrinary{ +func (this *BCTCurl) Squeeze(tritCount int) ternary.BCTrits { + result := ternary.BCTrits{ Lo: make([]uint, tritCount), Hi: make([]uint, tritCount), } diff --git a/packages/curl/curl.go b/packages/curl/curl.go index 4c19bb3170c0c4c4b8dd4f0dac48f18f45064b2d..9409050aaa4cdcf25cbafe7c908d9ac4439ed77a 100644 --- a/packages/curl/curl.go +++ b/packages/curl/curl.go @@ -45,10 +45,10 @@ func (curl *Curl) Initialize() { curl.InitializeCurl(nil, 0, curl.rounds) } -func (curl *Curl) InitializeCurl(trinary ternary.Trits, length int, rounds int) { +func (curl *Curl) InitializeCurl(trits ternary.Trits, length int, rounds int) { curl.rounds = rounds - if trinary != nil { - curl.state = trinary + if trits != nil { + curl.state = trits } else { curl.state = make(ternary.Trits, STATE_LENGTH) } @@ -58,10 +58,10 @@ func (curl *Curl) Reset() { curl.InitializeCurl(nil, 0, curl.rounds) } -func (curl *Curl) Absorb(trinary ternary.Trits, offset int, length int) { +func (curl *Curl) Absorb(trits ternary.Trits, offset int, length int) { for { limit := int(math.Min(HASH_LENGTH, float64(length))) - copy(curl.state, trinary[offset:offset+limit]) + copy(curl.state, trits[offset:offset+limit]) curl.Transform() offset += HASH_LENGTH length -= HASH_LENGTH diff --git a/packages/iac/area.go b/packages/iac/area.go index 49fd6e57ae1884efae12d097bc2b9d9c67c448ed..d30b7899501587d836921e21f4245ef3a1d0921c 100644 --- a/packages/iac/area.go +++ b/packages/iac/area.go @@ -9,7 +9,7 @@ import ( type Area struct { olc.CodeArea - IACCode ternary.Trinary + IACCode ternary.Trytes OLCCode string } diff --git a/packages/iac/iac.go b/packages/iac/iac.go index 02e860dbed7d4b6962d359d5d1e3347c55ccd221..ff61d604ef54aea3ab4996a6707f570b28d32777 100644 --- a/packages/iac/iac.go +++ b/packages/iac/iac.go @@ -6,13 +6,13 @@ import ( "github.com/iotaledger/goshimmer/packages/ternary" ) -func Decode(trinary ternary.Trinary) (result *Area, err errors.IdentifiableError) { - if olcCode, conversionErr := OLCCodeFromTrinary(trinary); conversionErr != nil { +func Decode(trytes ternary.Trytes) (result *Area, err errors.IdentifiableError) { + if olcCode, conversionErr := OLCCodeFromTrytes(trytes); conversionErr != nil { err = conversionErr } else { if codeArea, olcErr := olc.Decode(olcCode); olcErr == nil { result = &Area{ - IACCode: trinary, + IACCode: trytes, OLCCode: olcCode, CodeArea: codeArea, } diff --git a/packages/iac/olc_conversion.go b/packages/iac/olc_conversion.go index ef0cea481acef7c2309cdba164cf46b0fe504109..053ea85259660dbf60ce00583841cfc0be05d475 100644 --- a/packages/iac/olc_conversion.go +++ b/packages/iac/olc_conversion.go @@ -31,10 +31,10 @@ func init() { IAC_TO_OLC_MAP[IAC_PADDING] = OLC_PADDING } -func TrinaryFromOLCCode(code string) (result ternary.Trinary, err errors.IdentifiableError) { +func TrytesFromOLCCode(code string) (result ternary.Trytes, err errors.IdentifiableError) { for _, char := range code { if translatedChar, exists := OLC_TO_IAC_MAP[char]; exists { - result += ternary.Trinary(translatedChar) + result += ternary.Trytes(translatedChar) } else { err = ErrConversionFailed.Derive("invalid character in input") } @@ -43,8 +43,8 @@ func TrinaryFromOLCCode(code string) (result ternary.Trinary, err errors.Identif return } -func OLCCodeFromTrinary(trinary ternary.Trinary) (result string, err errors.IdentifiableError) { - for _, char := range trinary { +func OLCCodeFromTrytes(trytes ternary.Trytes) (result string, err errors.IdentifiableError) { + for _, char := range trytes { if translatedChar, exists := IAC_TO_OLC_MAP[char]; exists { result += string(translatedChar) } else { diff --git a/packages/model/approvers/approvers.go b/packages/model/approvers/approvers.go index 3f74b5ea7cebf3b1a6b62e2707b4c136296d058f..153968fabdf9ec449f20d126ddd0bf7b7008a38d 100644 --- a/packages/model/approvers/approvers.go +++ b/packages/model/approvers/approvers.go @@ -11,35 +11,35 @@ import ( ) type Approvers struct { - hash ternary.Trinary - hashes map[ternary.Trinary]bool + hash ternary.Trytes + hashes map[ternary.Trytes]bool hashesMutex sync.RWMutex modified bool } -func New(hash ternary.Trinary) *Approvers { +func New(hash ternary.Trytes) *Approvers { return &Approvers{ hash: hash, - hashes: make(map[ternary.Trinary]bool), + hashes: make(map[ternary.Trytes]bool), modified: false, } } // region public methods with locking ////////////////////////////////////////////////////////////////////////////////// -func (approvers *Approvers) Add(transactionHash ternary.Trinary) { +func (approvers *Approvers) Add(transactionHash ternary.Trytes) { approvers.hashesMutex.Lock() approvers.add(transactionHash) approvers.hashesMutex.Unlock() } -func (approvers *Approvers) Remove(approverHash ternary.Trinary) { +func (approvers *Approvers) Remove(approverHash ternary.Trytes) { approvers.hashesMutex.Lock() approvers.remove(approverHash) approvers.hashesMutex.Unlock() } -func (approvers *Approvers) GetHashes() (result []ternary.Trinary) { +func (approvers *Approvers) GetHashes() (result []ternary.Trytes) { approvers.hashesMutex.RLock() result = approvers.getHashes() approvers.hashesMutex.RUnlock() @@ -47,7 +47,7 @@ func (approvers *Approvers) GetHashes() (result []ternary.Trinary) { return } -func (approvers *Approvers) GetHash() (result ternary.Trinary) { +func (approvers *Approvers) GetHash() (result ternary.Trytes) { approvers.hashesMutex.RLock() result = approvers.hash approvers.hashesMutex.RUnlock() @@ -101,13 +101,13 @@ func (approvers *Approvers) Unmarshal(data []byte) (err errors.IdentifiableError approvers.hashesMutex.Lock() - approvers.hash = ternary.Trinary(typeutils.BytesToString(data[MARSHALED_APPROVERS_HASH_START:MARSHALED_APPROVERS_HASH_END])) - approvers.hashes = make(map[ternary.Trinary]bool, hashesCount) + approvers.hash = ternary.Trytes(typeutils.BytesToString(data[MARSHALED_APPROVERS_HASH_START:MARSHALED_APPROVERS_HASH_END])) + approvers.hashes = make(map[ternary.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[ternary.Trinary(typeutils.BytesToString(data[HASH_START:HASH_END]))] = true + approvers.hashes[ternary.Trytes(typeutils.BytesToString(data[HASH_START:HASH_END]))] = true } approvers.hashesMutex.Unlock() @@ -119,22 +119,22 @@ func (approvers *Approvers) Unmarshal(data []byte) (err errors.IdentifiableError // region private methods without locking ////////////////////////////////////////////////////////////////////////////// -func (approvers *Approvers) add(transactionHash ternary.Trinary) { +func (approvers *Approvers) add(transactionHash ternary.Trytes) { if _, exists := approvers.hashes[transactionHash]; !exists { approvers.hashes[transactionHash] = true approvers.modified = true } } -func (approvers *Approvers) remove(approverHash ternary.Trinary) { +func (approvers *Approvers) remove(approverHash ternary.Trytes) { if _, exists := approvers.hashes[approverHash]; exists { delete(approvers.hashes, approverHash) approvers.modified = true } } -func (approvers *Approvers) getHashes() (result []ternary.Trinary) { - result = make([]ternary.Trinary, len(approvers.hashes)) +func (approvers *Approvers) getHashes() (result []ternary.Trytes) { + result = make([]ternary.Trytes, len(approvers.hashes)) counter := 0 for hash := range approvers.hashes { diff --git a/packages/model/meta_transaction/constants.go b/packages/model/meta_transaction/constants.go index 498b5798160d59feb6b1bc0690404078675428ba..48fe6869ea278e148d4a477a0af614004f72a472 100644 --- a/packages/model/meta_transaction/constants.go +++ b/packages/model/meta_transaction/constants.go @@ -31,5 +31,5 @@ const ( MARSHALLED_TOTAL_SIZE = DATA_END - BRANCH_NULL_HASH = ternary.Trinary("999999999999999999999999999999999999999999999999999999999999999999999999999999999") + BRANCH_NULL_HASH = ternary.Trytes("999999999999999999999999999999999999999999999999999999999999999999999999999999999") ) diff --git a/packages/model/meta_transaction/meta_transaction.go b/packages/model/meta_transaction/meta_transaction.go index 456e7e36f57dd58278ba81f8354671caacd9a69e..82bb790c31ba802e1df8eb16b4c099856cc090bf 100644 --- a/packages/model/meta_transaction/meta_transaction.go +++ b/packages/model/meta_transaction/meta_transaction.go @@ -8,15 +8,15 @@ import ( ) type MetaTransaction struct { - hash *ternary.Trinary + hash *ternary.Trytes weightMagnitude int - shardMarker *ternary.Trinary - trunkTransactionHash *ternary.Trinary - branchTransactionHash *ternary.Trinary + shardMarker *ternary.Trytes + trunkTransactionHash *ternary.Trytes + branchTransactionHash *ternary.Trytes head *bool tail *bool - transactionType *ternary.Trinary + transactionType *ternary.Trytes data ternary.Trits modified bool @@ -72,7 +72,7 @@ func (this *MetaTransaction) ReHash() { } // retrieves the hash of the transaction -func (this *MetaTransaction) GetHash() (result ternary.Trinary) { +func (this *MetaTransaction) GetHash() (result ternary.Trytes) { this.hashMutex.RLock() if this.hash == nil { this.hashMutex.RUnlock() @@ -116,21 +116,21 @@ func (this *MetaTransaction) GetWeightMagnitude() (result int) { // hashes the transaction using curl (without locking - internal usage) func (this *MetaTransaction) parseHashRelatedDetails() { hashTrits := <-curl.CURLP81.Hash(this.trits) - hashTrinary := hashTrits.ToTrinary() + hashTrytes := hashTrits.ToTrytes() - this.hash = &hashTrinary + this.hash = &hashTrytes this.weightMagnitude = hashTrits.TrailingZeroes() } // getter for the shard marker (supports concurrency) -func (this *MetaTransaction) GetShardMarker() (result ternary.Trinary) { +func (this *MetaTransaction) GetShardMarker() (result ternary.Trytes) { this.shardMarkerMutex.RLock() if this.shardMarker == nil { this.shardMarkerMutex.RUnlock() this.shardMarkerMutex.Lock() defer this.shardMarkerMutex.Unlock() if this.shardMarker == nil { - shardMarker := this.trits[SHARD_MARKER_OFFSET:SHARD_MARKER_END].ToTrinary() + shardMarker := this.trits[SHARD_MARKER_OFFSET:SHARD_MARKER_END].ToTrytes() this.shardMarker = &shardMarker } @@ -144,7 +144,7 @@ func (this *MetaTransaction) GetShardMarker() (result ternary.Trinary) { } // setter for the shard marker (supports concurrency) -func (this *MetaTransaction) SetShardMarker(shardMarker ternary.Trinary) bool { +func (this *MetaTransaction) SetShardMarker(shardMarker ternary.Trytes) bool { this.shardMarkerMutex.RLock() if this.shardMarker == nil || *this.shardMarker != shardMarker { this.shardMarkerMutex.RUnlock() @@ -170,14 +170,14 @@ func (this *MetaTransaction) SetShardMarker(shardMarker ternary.Trinary) bool { } // getter for the bundleHash (supports concurrency) -func (this *MetaTransaction) GetTrunkTransactionHash() (result ternary.Trinary) { +func (this *MetaTransaction) GetTrunkTransactionHash() (result ternary.Trytes) { this.trunkTransactionHashMutex.RLock() if this.trunkTransactionHash == nil { this.trunkTransactionHashMutex.RUnlock() this.trunkTransactionHashMutex.Lock() defer this.trunkTransactionHashMutex.Unlock() if this.trunkTransactionHash == nil { - trunkTransactionHash := this.trits[TRUNK_TRANSACTION_HASH_OFFSET:TRUNK_TRANSACTION_HASH_END].ToTrinary() + trunkTransactionHash := this.trits[TRUNK_TRANSACTION_HASH_OFFSET:TRUNK_TRANSACTION_HASH_END].ToTrytes() this.trunkTransactionHash = &trunkTransactionHash } @@ -191,7 +191,7 @@ func (this *MetaTransaction) GetTrunkTransactionHash() (result ternary.Trinary) } // setter for the trunkTransactionHash (supports concurrency) -func (this *MetaTransaction) SetTrunkTransactionHash(trunkTransactionHash ternary.Trinary) bool { +func (this *MetaTransaction) SetTrunkTransactionHash(trunkTransactionHash ternary.Trytes) bool { this.trunkTransactionHashMutex.RLock() if this.trunkTransactionHash == nil || *this.trunkTransactionHash != trunkTransactionHash { this.trunkTransactionHashMutex.RUnlock() @@ -217,14 +217,14 @@ func (this *MetaTransaction) SetTrunkTransactionHash(trunkTransactionHash ternar } // getter for the bundleHash (supports concurrency) -func (this *MetaTransaction) GetBranchTransactionHash() (result ternary.Trinary) { +func (this *MetaTransaction) GetBranchTransactionHash() (result ternary.Trytes) { this.branchTransactionHashMutex.RLock() if this.branchTransactionHash == nil { this.branchTransactionHashMutex.RUnlock() this.branchTransactionHashMutex.Lock() defer this.branchTransactionHashMutex.Unlock() if this.branchTransactionHash == nil { - branchTransactionHash := this.trits[BRANCH_TRANSACTION_HASH_OFFSET:BRANCH_TRANSACTION_HASH_END].ToTrinary() + branchTransactionHash := this.trits[BRANCH_TRANSACTION_HASH_OFFSET:BRANCH_TRANSACTION_HASH_END].ToTrytes() this.branchTransactionHash = &branchTransactionHash } @@ -238,7 +238,7 @@ func (this *MetaTransaction) GetBranchTransactionHash() (result ternary.Trinary) } // setter for the trunkTransactionHash (supports concurrency) -func (this *MetaTransaction) SetBranchTransactionHash(branchTransactionHash ternary.Trinary) bool { +func (this *MetaTransaction) SetBranchTransactionHash(branchTransactionHash ternary.Trytes) bool { this.branchTransactionHashMutex.RLock() if this.branchTransactionHash == nil || *this.branchTransactionHash != branchTransactionHash { this.branchTransactionHashMutex.RUnlock() @@ -366,14 +366,14 @@ func (this *MetaTransaction) SetTail(tail bool) bool { } // getter for the transaction type (supports concurrency) -func (this *MetaTransaction) GetTransactionType() (result ternary.Trinary) { +func (this *MetaTransaction) GetTransactionType() (result ternary.Trytes) { this.transactionTypeMutex.RLock() if this.transactionType == nil { this.transactionTypeMutex.RUnlock() this.transactionTypeMutex.Lock() defer this.transactionTypeMutex.Unlock() if this.transactionType == nil { - transactionType := this.trits[TRANSACTION_TYPE_OFFSET:TRANSACTION_TYPE_END].ToTrinary() + transactionType := this.trits[TRANSACTION_TYPE_OFFSET:TRANSACTION_TYPE_END].ToTrytes() this.transactionType = &transactionType } @@ -387,7 +387,7 @@ func (this *MetaTransaction) GetTransactionType() (result ternary.Trinary) { } // setter for the transaction type (supports concurrency) -func (this *MetaTransaction) SetTransactionType(transactionType ternary.Trinary) bool { +func (this *MetaTransaction) SetTransactionType(transactionType ternary.Trytes) bool { this.transactionTypeMutex.RLock() if this.transactionType == nil || *this.transactionType != transactionType { this.transactionTypeMutex.RUnlock() diff --git a/packages/model/meta_transaction/meta_transaction_test.go b/packages/model/meta_transaction/meta_transaction_test.go index 1c73e4b4b03d97a61fe717fdd01c6ab01d9e66ba..996cc8a1be55db5753cd6961fcfeaee68ed25b94 100644 --- a/packages/model/meta_transaction/meta_transaction_test.go +++ b/packages/model/meta_transaction/meta_transaction_test.go @@ -10,12 +10,12 @@ import ( ) func TestMetaTransaction_SettersGetters(t *testing.T) { - shardMarker := ternary.Trinary("NPHTQORL9XKA") - trunkTransactionHash := ternary.Trinary("99999999999999999999999999999999999999999999999999999999999999999999999999999999A") - branchTransactionHash := ternary.Trinary("99999999999999999999999999999999999999999999999999999999999999999999999999999999B") + shardMarker := ternary.Trytes("NPHTQORL9XKA") + trunkTransactionHash := ternary.Trytes("99999999999999999999999999999999999999999999999999999999999999999999999999999999A") + branchTransactionHash := ternary.Trytes("99999999999999999999999999999999999999999999999999999999999999999999999999999999B") head := true tail := true - transactionType := ternary.Trinary("9999999999999999999999") + transactionType := ternary.Trytes("9999999999999999999999") transaction := New() transaction.SetShardMarker(shardMarker) diff --git a/packages/model/transactionmetadata/transactionmetadata.go b/packages/model/transactionmetadata/transactionmetadata.go index df255a22d3f39b75f09113e20fd7b2b969ddb0cc..39874a5addf16bd54ed3b9588b98b41d93df3c9f 100644 --- a/packages/model/transactionmetadata/transactionmetadata.go +++ b/packages/model/transactionmetadata/transactionmetadata.go @@ -13,7 +13,7 @@ import ( // region type definition and constructor ////////////////////////////////////////////////////////////////////////////// type TransactionMetadata struct { - hash ternary.Trinary + hash ternary.Trytes hashMutex sync.RWMutex receivedTime time.Time receivedTimeMutex sync.RWMutex @@ -27,7 +27,7 @@ type TransactionMetadata struct { modifiedMutex sync.RWMutex } -func New(hash ternary.Trinary) *TransactionMetadata { +func New(hash ternary.Trytes) *TransactionMetadata { return &TransactionMetadata{ hash: hash, receivedTime: time.Now(), @@ -42,14 +42,14 @@ func New(hash ternary.Trinary) *TransactionMetadata { // region getters and setters ////////////////////////////////////////////////////////////////////////////////////////// -func (metadata *TransactionMetadata) GetHash() ternary.Trinary { +func (metadata *TransactionMetadata) GetHash() ternary.Trytes { metadata.hashMutex.RLock() defer metadata.hashMutex.RUnlock() return metadata.hash } -func (metadata *TransactionMetadata) SetHash(hash ternary.Trinary) { +func (metadata *TransactionMetadata) SetHash(hash ternary.Trytes) { metadata.hashMutex.RLock() if metadata.hash != hash { metadata.hashMutex.RUnlock() @@ -228,7 +228,7 @@ func (metadata *TransactionMetadata) Unmarshal(data []byte) errors.IdentifiableE metadata.finalizedMutex.Lock() defer metadata.finalizedMutex.Unlock() - metadata.hash = ternary.Trinary(typeutils.BytesToString(data[MARSHALED_HASH_START:MARSHALED_HASH_END])) + metadata.hash = ternary.Trytes(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 ErrUnmarshalFailed.Derive(err, "could not unmarshal the received time") diff --git a/packages/model/value_transaction/value_transaction.go b/packages/model/value_transaction/value_transaction.go index 6eff46bf9b0521cca88cf7552e549c8e7cafefd8..37b2bfbc13ca00c671db142ead215972c8e8370d 100644 --- a/packages/model/value_transaction/value_transaction.go +++ b/packages/model/value_transaction/value_transaction.go @@ -10,15 +10,15 @@ import ( type ValueTransaction struct { *meta_transaction.MetaTransaction - address *ternary.Trinary + address *ternary.Trytes addressMutex sync.RWMutex value *int64 valueMutex sync.RWMutex timestamp *uint timestampMutex sync.RWMutex - nonce *ternary.Trinary + nonce *ternary.Trytes nonceMutex sync.RWMutex - signatureMessageFragment *ternary.Trinary + signatureMessageFragment *ternary.Trytes signatureMessageFragmentMutex sync.RWMutex trits ternary.Trits @@ -52,14 +52,14 @@ func FromBytes(bytes []byte) (result *ValueTransaction) { } // getter for the address (supports concurrency) -func (this *ValueTransaction) GetAddress() (result ternary.Trinary) { +func (this *ValueTransaction) GetAddress() (result ternary.Trytes) { this.addressMutex.RLock() if this.address == nil { this.addressMutex.RUnlock() this.addressMutex.Lock() defer this.addressMutex.Unlock() if this.address == nil { - address := this.trits[ADDRESS_OFFSET:ADDRESS_END].ToTrinary() + address := this.trits[ADDRESS_OFFSET:ADDRESS_END].ToTrytes() this.address = &address } @@ -73,7 +73,7 @@ func (this *ValueTransaction) GetAddress() (result ternary.Trinary) { } // setter for the address (supports concurrency) -func (this *ValueTransaction) SetAddress(address ternary.Trinary) bool { +func (this *ValueTransaction) SetAddress(address ternary.Trytes) bool { this.addressMutex.RLock() if this.address == nil || *this.address != address { this.addressMutex.RUnlock() @@ -193,14 +193,14 @@ func (this *ValueTransaction) SetTimestamp(timestamp uint) bool { } // getter for the nonce (supports concurrency) -func (this *ValueTransaction) GetNonce() (result ternary.Trinary) { +func (this *ValueTransaction) GetNonce() (result ternary.Trytes) { this.nonceMutex.RLock() if this.nonce == nil { this.nonceMutex.RUnlock() this.nonceMutex.Lock() defer this.nonceMutex.Unlock() if this.nonce == nil { - nonce := this.trits[NONCE_OFFSET:NONCE_END].ToTrinary() + nonce := this.trits[NONCE_OFFSET:NONCE_END].ToTrytes() this.nonce = &nonce } @@ -214,7 +214,7 @@ func (this *ValueTransaction) GetNonce() (result ternary.Trinary) { } // setter for the nonce (supports concurrency) -func (this *ValueTransaction) SetNonce(nonce ternary.Trinary) bool { +func (this *ValueTransaction) SetNonce(nonce ternary.Trytes) bool { this.nonceMutex.RLock() if this.nonce == nil || *this.nonce != nonce { this.nonceMutex.RUnlock() @@ -240,14 +240,14 @@ func (this *ValueTransaction) SetNonce(nonce ternary.Trinary) bool { } // getter for the signatureMessageFragmetn (supports concurrency) -func (this *ValueTransaction) GetSignatureMessageFragment() (result ternary.Trinary) { +func (this *ValueTransaction) GetSignatureMessageFragment() (result ternary.Trytes) { this.signatureMessageFragmentMutex.RLock() if this.signatureMessageFragment == nil { this.signatureMessageFragmentMutex.RUnlock() this.signatureMessageFragmentMutex.Lock() defer this.signatureMessageFragmentMutex.Unlock() if this.signatureMessageFragment == nil { - signatureMessageFragment := this.trits[SIGNATURE_MESSAGE_FRAGMENT_OFFSET:SIGNATURE_MESSAGE_FRAGMENT_END].ToTrinary() + signatureMessageFragment := this.trits[SIGNATURE_MESSAGE_FRAGMENT_OFFSET:SIGNATURE_MESSAGE_FRAGMENT_END].ToTrytes() this.signatureMessageFragment = &signatureMessageFragment } @@ -261,7 +261,7 @@ func (this *ValueTransaction) GetSignatureMessageFragment() (result ternary.Trin } // setter for the nonce (supports concurrency) -func (this *ValueTransaction) SetSignatureMessageFragment(signatureMessageFragment ternary.Trinary) bool { +func (this *ValueTransaction) SetSignatureMessageFragment(signatureMessageFragment ternary.Trytes) bool { this.signatureMessageFragmentMutex.RLock() if this.signatureMessageFragment == nil || *this.signatureMessageFragment != signatureMessageFragment { this.signatureMessageFragmentMutex.RUnlock() diff --git a/packages/model/value_transaction/value_transaction_test.go b/packages/model/value_transaction/value_transaction_test.go index 35d3197f57e4d422dd4a528686d808cbadc2ce8c..dcc6eb39e6f6dbf1174df0f72143ed7313dac3a7 100644 --- a/packages/model/value_transaction/value_transaction_test.go +++ b/packages/model/value_transaction/value_transaction_test.go @@ -9,7 +9,7 @@ import ( ) func TestValueTransaction_SettersGetters(t *testing.T) { - address := ternary.Trinary("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") + address := ternary.Trytes("A9999999999999999999999999999999999999999999999999999999999999999999999999999999F") transaction := New() transaction.SetAddress(address) diff --git a/packages/ternary/bc_ternary.go b/packages/ternary/bc_ternary.go index d18258c03e4b290d66646f118400be8ff8d03f10..cc7432ca0f0a2a3d5840d26fdc8fa546d2bb4725 100644 --- a/packages/ternary/bc_ternary.go +++ b/packages/ternary/bc_ternary.go @@ -6,8 +6,8 @@ type BCTrit struct { Hi uint } -// a Binary Coded Trinary consists out of many Binary Coded Trits -type BCTrinary struct { +// a Binary Coded Trytes consists out of many Binary Coded Trits +type BCTrits struct { Lo []uint Hi []uint } diff --git a/packages/ternary/bc_ternary_demultiplexer.go b/packages/ternary/bc_ternary_demultiplexer.go index 6030f7a29958db990bc0bc098b3c2cd88a4bef5d..cebbd95bce5aeecc54c197404b7cc63218c1fd0d 100644 --- a/packages/ternary/bc_ternary_demultiplexer.go +++ b/packages/ternary/bc_ternary_demultiplexer.go @@ -1,22 +1,22 @@ package ternary type BCTernaryDemultiplexer struct { - bcTrinary BCTrinary + bcTrits BCTrits } -func NewBCTernaryDemultiplexer(bcTrinary BCTrinary) *BCTernaryDemultiplexer { - this := &BCTernaryDemultiplexer{bcTrinary: bcTrinary} +func NewBCTernaryDemultiplexer(bcTrits BCTrits) *BCTernaryDemultiplexer { + this := &BCTernaryDemultiplexer{bcTrits: bcTrits} return this } func (this *BCTernaryDemultiplexer) Get(index int) Trits { - length := len(this.bcTrinary.Lo) + length := len(this.bcTrits.Lo) result := make(Trits, length) for i := 0; i < length; i++ { - low := (this.bcTrinary.Lo[i] >> uint(index)) & 1 - hi := (this.bcTrinary.Hi[i] >> uint(index)) & 1 + low := (this.bcTrits.Lo[i] >> uint(index)) & 1 + hi := (this.bcTrits.Hi[i] >> uint(index)) & 1 switch true { case low == 1 && hi == 0: diff --git a/packages/ternary/bc_ternary_multiplexer.go b/packages/ternary/bc_ternary_multiplexer.go index d84e5a782e5a74b10f315fd6b71895beef64d280..b822e8b2c25b7c94f17abbae3ca72a2e866e04b7 100644 --- a/packages/ternary/bc_ternary_multiplexer.go +++ b/packages/ternary/bc_ternary_multiplexer.go @@ -15,8 +15,8 @@ func NewBCTernaryMultiplexer() *BCTernaryMultiplexer { return this } -func (this *BCTernaryMultiplexer) Add(trinary Trits) int { - this.trinaries = append(this.trinaries, trinary) +func (this *BCTernaryMultiplexer) Add(trits Trits) int { + this.trinaries = append(this.trinaries, trits) return len(this.trinaries) - 1 } @@ -25,11 +25,11 @@ func (this *BCTernaryMultiplexer) Get(index int) Trits { return this.trinaries[index] } -func (this *BCTernaryMultiplexer) Extract() (BCTrinary, error) { +func (this *BCTernaryMultiplexer) Extract() (BCTrits, error) { trinariesCount := len(this.trinaries) tritsCount := len(this.trinaries[0]) - result := BCTrinary{ + result := BCTrits{ Lo: make([]uint, tritsCount), Hi: make([]uint, tritsCount), } @@ -50,7 +50,7 @@ func (this *BCTernaryMultiplexer) Extract() (BCTrinary, error) { bcTrit.Hi |= 1 << uint(j) default: - return result, errors.New("Invalid trit #" + strconv.Itoa(i) + " in trinary #" + strconv.Itoa(j)) + return result, errors.New("Invalid trit #" + strconv.Itoa(i) + " in trits #" + strconv.Itoa(j)) } } diff --git a/packages/ternary/ternary.go b/packages/ternary/ternary.go index 745ca3542b18c9f8b0bb61ab2a804d18f7f036dd..31ada8e4465e97a1953cee8e51f493c863bfc0cb 100644 --- a/packages/ternary/ternary.go +++ b/packages/ternary/ternary.go @@ -11,19 +11,19 @@ type Trit = int8 // Trits consists out of many Trits type Trits []Trit -// Trinary is a string representation of the Trits -type Trinary string +// Trytes is a string representation of the Trits +type Trytes string -// simply changes the type of this Trinary to a byte array without copying any data -func (trinary Trinary) CastToBytes() []byte { - hdr := (*reflect.StringHeader)(unsafe.Pointer(&trinary)) +// simply changes the type of this Trytes to a byte array without copying any data +func (trytes Trytes) CastToBytes() []byte { + hdr := (*reflect.StringHeader)(unsafe.Pointer(&trytes)) return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{Data: hdr.Data, Len: hdr.Len, Cap: hdr.Len})) } -func (trinary Trinary) ToTrits() Trits { - trits := make(Trits, 0, len(trinary)*NUMBER_OF_TRITS_IN_A_TRYTE) - for _, char := range trinary { +func (trytes Trytes) ToTrits() Trits { + trits := make(Trits, 0, len(trytes)*NUMBER_OF_TRITS_IN_A_TRYTE) + for _, char := range trytes { trits = append(trits, TRYTES_TO_TRITS_MAP[char]...) } @@ -96,6 +96,6 @@ func (this Trits) ToString() string { return TritsToString(this, 0, len(this)) } -func (this Trits) ToTrinary() Trinary { - return Trinary(TritsToString(this, 0, len(this))) +func (this Trits) ToTrytes() Trytes { + return Trytes(TritsToString(this, 0, len(this))) } diff --git a/plugins/tangle/approvers.go b/plugins/tangle/approvers.go index 72c659d97e6534de27869f0b4867cfff74525b07..2e54e11d97f206b58f42d9c858a73f9626b10cc3 100644 --- a/plugins/tangle/approvers.go +++ b/plugins/tangle/approvers.go @@ -12,7 +12,8 @@ import ( // region global public api //////////////////////////////////////////////////////////////////////////////////////////// -func GetApprovers(transactionHash ternary.Trinary, computeIfAbsent ...func(ternary.Trinary) *approvers.Approvers) (result *approvers.Approvers, err errors.IdentifiableError) { +// GetApprovers retrieves approvers from the database. +func GetApprovers(transactionHash ternary.Trytes, computeIfAbsent ...func(ternary.Trytes) *approvers.Approvers) (result *approvers.Approvers, err errors.IdentifiableError) { if cacheResult := approversCache.ComputeIfAbsent(transactionHash, func() interface{} { if dbApprovers, dbErr := getApproversFromDatabase(transactionHash); dbErr != nil { err = dbErr @@ -34,7 +35,7 @@ func GetApprovers(transactionHash ternary.Trinary, computeIfAbsent ...func(terna return } -func ContainsApprovers(transactionHash ternary.Trinary) (result bool, err errors.IdentifiableError) { +func ContainsApprovers(transactionHash ternary.Trytes) (result bool, err errors.IdentifiableError) { if approversCache.Contains(transactionHash) { result = true } else { @@ -94,14 +95,14 @@ func storeApproversInDatabase(approvers *approvers.Approvers) errors.Identifiabl return nil } -func getApproversFromDatabase(transactionHash ternary.Trinary) (*approvers.Approvers, errors.IdentifiableError) { +func getApproversFromDatabase(transactionHash ternary.Trytes) (*approvers.Approvers, errors.IdentifiableError) { approversData, err := approversDatabase.Get(transactionHash.CastToBytes()) if err != nil { if err == badger.ErrKeyNotFound { return nil, nil - } else { - return nil, ErrDatabaseError.Derive(err, "failed to retrieve approvers") } + + return nil, ErrDatabaseError.Derive(err, "failed to retrieve approvers") } var result approvers.Approvers @@ -112,7 +113,7 @@ func getApproversFromDatabase(transactionHash ternary.Trinary) (*approvers.Appro return &result, nil } -func databaseContainsApprovers(transactionHash ternary.Trinary) (bool, errors.IdentifiableError) { +func databaseContainsApprovers(transactionHash ternary.Trytes) (bool, errors.IdentifiableError) { if contains, err := approversDatabase.Contains(transactionHash.CastToBytes()); err != nil { return false, ErrDatabaseError.Derive(err, "failed to check if the approvers exists") } else { diff --git a/plugins/tangle/solidifier.go b/plugins/tangle/solidifier.go index 7b9e6c8c755d9ed62f8705cef3ca6fce900d756b..b5589efec5acfe05c0bd70211147969eff0316e4 100644 --- a/plugins/tangle/solidifier.go +++ b/plugins/tangle/solidifier.go @@ -114,7 +114,7 @@ func IsSolid(transaction *value_transaction.ValueTransaction) (bool, errors.Iden return false, nil } -func propagateSolidity(transactionHash ternary.Trinary) errors.IdentifiableError { +func propagateSolidity(transactionHash ternary.Trytes) errors.IdentifiableError { if approvers, err := GetApprovers(transactionHash, approvers.New); err != nil { return err } else { @@ -138,7 +138,7 @@ func propagateSolidity(transactionHash ternary.Trinary) errors.IdentifiableError func processMetaTransaction(plugin *node.Plugin, metaTransaction *meta_transaction.MetaTransaction) { var newTransaction bool - if tx, err := GetTransaction(metaTransaction.GetHash(), func(transactionHash ternary.Trinary) *value_transaction.ValueTransaction { + if tx, err := GetTransaction(metaTransaction.GetHash(), func(transactionHash ternary.Trytes) *value_transaction.ValueTransaction { newTransaction = true return value_transaction.FromMetaTransaction(metaTransaction) diff --git a/plugins/tangle/solidifier_test.go b/plugins/tangle/solidifier_test.go index de7ae69fe1684bd70ac9a8f16abd2b9d0b2d010a..c35e8a9fd105115c57f6b52322cae88d97effe96 100644 --- a/plugins/tangle/solidifier_test.go +++ b/plugins/tangle/solidifier_test.go @@ -19,7 +19,7 @@ func TestSolidifier(t *testing.T) { // create transactions and chain them together transaction1 := value_transaction.New() - transaction1.SetNonce(ternary.Trinary("99999999999999999999999999A")) + transaction1.SetNonce(ternary.Trytes("99999999999999999999999999A")) transaction2 := value_transaction.New() transaction2.SetBranchTransactionHash(transaction1.GetHash()) transaction3 := value_transaction.New() diff --git a/plugins/tangle/transaction.go b/plugins/tangle/transaction.go index 22913eddb7fce9566648a781ae3fdf441e3518d5..be61b95c12e859f2f7c441cbfcbb8e7235d9c555 100644 --- a/plugins/tangle/transaction.go +++ b/plugins/tangle/transaction.go @@ -13,7 +13,7 @@ import ( // region public api /////////////////////////////////////////////////////////////////////////////////////////////////// -func GetTransaction(transactionHash ternary.Trinary, computeIfAbsent ...func(ternary.Trinary) *value_transaction.ValueTransaction) (result *value_transaction.ValueTransaction, err errors.IdentifiableError) { +func GetTransaction(transactionHash ternary.Trytes, computeIfAbsent ...func(ternary.Trytes) *value_transaction.ValueTransaction) (result *value_transaction.ValueTransaction, err errors.IdentifiableError) { if cacheResult := transactionCache.ComputeIfAbsent(transactionHash, func() interface{} { if transaction, dbErr := getTransactionFromDatabase(transactionHash); dbErr != nil { err = dbErr @@ -35,7 +35,7 @@ func GetTransaction(transactionHash ternary.Trinary, computeIfAbsent ...func(ter return } -func ContainsTransaction(transactionHash ternary.Trinary) (result bool, err errors.IdentifiableError) { +func ContainsTransaction(transactionHash ternary.Trytes) (result bool, err errors.IdentifiableError) { if transactionCache.Contains(transactionHash) { result = true } else { @@ -97,7 +97,7 @@ func storeTransactionInDatabase(transaction *value_transaction.ValueTransaction) return nil } -func getTransactionFromDatabase(transactionHash ternary.Trinary) (*value_transaction.ValueTransaction, errors.IdentifiableError) { +func getTransactionFromDatabase(transactionHash ternary.Trytes) (*value_transaction.ValueTransaction, errors.IdentifiableError) { txData, err := transactionDatabase.Get(transactionHash.CastToBytes()) if err != nil { if err == badger.ErrKeyNotFound { @@ -110,7 +110,7 @@ func getTransactionFromDatabase(transactionHash ternary.Trinary) (*value_transac return value_transaction.FromBytes(txData), nil } -func databaseContainsTransaction(transactionHash ternary.Trinary) (bool, errors.IdentifiableError) { +func databaseContainsTransaction(transactionHash ternary.Trytes) (bool, errors.IdentifiableError) { if contains, err := transactionDatabase.Contains(transactionHash.CastToBytes()); err != nil { return contains, ErrDatabaseError.Derive(err, "failed to check if the transaction exists") } else { diff --git a/plugins/tangle/transaction_metadata.go b/plugins/tangle/transaction_metadata.go index b7d056d17e9161417aed77fd357d01d67e2196bb..82a3b8fde8ac9a4053dc7c01f42f434d85a69524 100644 --- a/plugins/tangle/transaction_metadata.go +++ b/plugins/tangle/transaction_metadata.go @@ -13,7 +13,7 @@ import ( // region public api /////////////////////////////////////////////////////////////////////////////////////////////////// -func GetTransactionMetadata(transactionHash ternary.Trinary, computeIfAbsent ...func(ternary.Trinary) *transactionmetadata.TransactionMetadata) (result *transactionmetadata.TransactionMetadata, err errors.IdentifiableError) { +func GetTransactionMetadata(transactionHash ternary.Trytes, computeIfAbsent ...func(ternary.Trytes) *transactionmetadata.TransactionMetadata) (result *transactionmetadata.TransactionMetadata, err errors.IdentifiableError) { if cacheResult := transactionMetadataCache.ComputeIfAbsent(transactionHash, func() interface{} { if transactionMetadata, dbErr := getTransactionMetadataFromDatabase(transactionHash); dbErr != nil { err = dbErr @@ -35,7 +35,7 @@ func GetTransactionMetadata(transactionHash ternary.Trinary, computeIfAbsent ... return } -func ContainsTransactionMetadata(transactionHash ternary.Trinary) (result bool, err errors.IdentifiableError) { +func ContainsTransactionMetadata(transactionHash ternary.Trytes) (result bool, err errors.IdentifiableError) { if transactionMetadataCache.Contains(transactionHash) { result = true } else { @@ -101,7 +101,7 @@ func storeTransactionMetadataInDatabase(metadata *transactionmetadata.Transactio return nil } -func getTransactionMetadataFromDatabase(transactionHash ternary.Trinary) (*transactionmetadata.TransactionMetadata, errors.IdentifiableError) { +func getTransactionMetadataFromDatabase(transactionHash ternary.Trytes) (*transactionmetadata.TransactionMetadata, errors.IdentifiableError) { txMetadata, err := transactionMetadataDatabase.Get(transactionHash.CastToBytes()) if err != nil { if err == badger.ErrKeyNotFound { @@ -119,7 +119,7 @@ func getTransactionMetadataFromDatabase(transactionHash ternary.Trinary) (*trans return &result, nil } -func databaseContainsTransactionMetadata(transactionHash ternary.Trinary) (bool, errors.IdentifiableError) { +func databaseContainsTransactionMetadata(transactionHash ternary.Trytes) (bool, errors.IdentifiableError) { if contains, err := transactionMetadataDatabase.Contains(transactionHash.CastToBytes()); err != nil { return contains, ErrDatabaseError.Derive(err, "failed to check if the transaction metadata exists") } else { diff --git a/plugins/tipselection/tipselection.go b/plugins/tipselection/tipselection.go index 4457ddc026b922a3802e844d6b416677ef2af345..5c05fd4bb57aca59e63ad712e33136e0ac084e77 100644 --- a/plugins/tipselection/tipselection.go +++ b/plugins/tipselection/tipselection.go @@ -8,9 +8,9 @@ import ( var tips = datastructure.NewRandomMap() -func GetRandomTip() (result ternary.Trinary) { +func GetRandomTip() (result ternary.Trytes) { if randomTipHash := tips.RandomEntry(); randomTipHash != nil { - result = randomTipHash.(ternary.Trinary) + result = randomTipHash.(ternary.Trytes) } else { result = meta_transaction.BRANCH_NULL_HASH } diff --git a/plugins/webapi-gtta/plugin.go b/plugins/webapi-gtta/plugin.go index 3a97085736a984f78ea8df9528ba8d53b68d9721..6055ffdfdc5cf523d55a731ad1af3500735df36a 100644 --- a/plugins/webapi-gtta/plugin.go +++ b/plugins/webapi-gtta/plugin.go @@ -29,7 +29,7 @@ func Handler(c echo.Context) error { } type webResponse struct { - Duration int64 `json:"duration"` - BranchTransaction ternary.Trinary `json:"branchTransaction"` - TrunkTransaction ternary.Trinary `json:"trunkTransaction"` + Duration int64 `json:"duration"` + BranchTransaction ternary.Trytes `json:"branchTransaction"` + TrunkTransaction ternary.Trytes `json:"trunkTransaction"` }