-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2088 from ergoplatform/hashcode
Fix for block sections hashcode
- Loading branch information
Showing
22 changed files
with
150 additions
and
161 deletions.
There are no files selected for viewing
55 changes: 0 additions & 55 deletions
55
ergo-core/src/main/scala/org/ergoplatform/NodeViewModifier.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 7 additions & 3 deletions
10
ergo-core/src/main/scala/org/ergoplatform/modifiers/BlockSection.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 47 additions & 2 deletions
49
ergo-core/src/main/scala/org/ergoplatform/modifiers/ErgoNodeViewModifier.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,61 @@ | ||
package org.ergoplatform.modifiers | ||
|
||
import org.ergoplatform.core.BytesSerializable | ||
import org.ergoplatform.utils.ScorexEncoding | ||
import scorex.util.{ModifierId, bytesToId} | ||
import scorex.utils.Ints | ||
|
||
trait ErgoNodeViewModifier { self: BytesSerializable => | ||
/** | ||
* Basic trait for entities which are modifying internal blockchain view of the node, such as | ||
* unconfirmed transactions, block sections | ||
*/ | ||
trait ErgoNodeViewModifier extends BytesSerializable with ScorexEncoding { | ||
|
||
/** | ||
* @return cryptographically strong unique identifier of an object | ||
*/ | ||
def serializedId: Array[Byte] | ||
|
||
/** | ||
* identifier which can is friendly to data structures such as maps etc | ||
*/ | ||
lazy val id: ModifierId = bytesToId(serializedId) | ||
|
||
/** | ||
* Type of node view modifier (transaction, header etc) | ||
*/ | ||
val modifierTypeId: NetworkObjectTypeId.Value | ||
|
||
/** | ||
* Size of binary representation provided during object construction (to avoid serialization just to get the value) | ||
*/ | ||
val sizeOpt: Option[Int] | ||
|
||
/** | ||
* Cached size of binary representation | ||
*/ | ||
lazy val size: Int = sizeOpt.getOrElse(bytes.length) | ||
|
||
def serializedId: Array[Byte] | ||
/** | ||
* @return readable representation of `id`, as `id` is a hex-encoded string now, just identity functions is used | ||
*/ | ||
def encodedId: String = id | ||
|
||
override def equals(obj: scala.Any): Boolean = obj match { | ||
case that: ErgoNodeViewModifier => (that.id == id) && (that.modifierTypeId == modifierTypeId) | ||
case _ => false | ||
} | ||
|
||
override def hashCode(): Int = { | ||
Ints.fromByteArray(serializedId) | ||
} | ||
|
||
} | ||
|
||
object ErgoNodeViewModifier { | ||
/** | ||
* It is assumed that all the modifiers (offchain transactions, blocks, blockheaders etc) | ||
* have identifiers of the some length fixed with the ModifierIdSize constant | ||
*/ | ||
val ModifierIdSize: Int = 32 // in bytes | ||
} |
12 changes: 12 additions & 0 deletions
12
ergo-core/src/main/scala/org/ergoplatform/modifiers/TransactionsCarryingBlockSection.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.ergoplatform.modifiers | ||
|
||
import org.ergoplatform.modifiers.mempool.ErgoTransaction | ||
|
||
/** | ||
* Block section which contains transactions | ||
*/ | ||
trait TransactionsCarryingBlockSection extends BlockSection { | ||
|
||
def transactions: Seq[ErgoTransaction] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
ergo-core/src/main/scala/org/ergoplatform/modifiers/transaction/Signable.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.ergoplatform.modifiers.transaction | ||
|
||
|
||
/** | ||
* A basic trait for entities which can be signed | ||
*/ | ||
trait Signable { | ||
|
||
/** | ||
* Bytes to be signed | ||
*/ | ||
val messageToSign: Array[Byte] | ||
|
||
} |
18 changes: 0 additions & 18 deletions
18
ergo-core/src/main/scala/org/ergoplatform/modifiers/transaction/Transaction.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.