@@ -4,6 +4,7 @@ import akka.util.ByteString
4
4
import cats .implicits ._
5
5
import io .iohk .ethereum .consensus .blocks .BlockGenerator
6
6
import io .iohk .ethereum .domain .{Account , Address , Block , Blockchain , UInt256 }
7
+ import io .iohk .ethereum .jsonrpc .ProofService .StorageValueProof .asRlpSerializedNode
7
8
import io .iohk .ethereum .jsonrpc .ProofService .{GetProofRequest , GetProofResponse , ProofAccount , StorageProof , StorageProofKey , StorageValueProof }
8
9
import io .iohk .ethereum .mpt .{MptNode , MptTraversals }
9
10
import monix .eval .Task
@@ -24,7 +25,7 @@ object ProofService {
24
25
25
26
case class GetProofResponse (proofAccount : ProofAccount )
26
27
27
- trait StorageProof {
28
+ sealed trait StorageProof {
28
29
val key : StorageProofKey
29
30
val value : BigInt
30
31
val proof : Seq [ByteString ]
@@ -38,12 +39,20 @@ object ProofService {
38
39
*/
39
40
case class StorageValueProof (
40
41
key : StorageProofKey ,
41
- value : BigInt ,
42
- proof : Seq [ByteString ]) extends StorageProof
42
+ value : BigInt = BigInt ( 0 ) ,
43
+ proof : Seq [ByteString ] = Seq .empty[ MptNode ].map(asRlpSerializedNode) ) extends StorageProof
43
44
44
45
object StorageValueProof {
45
- def apply (key : BigInt , value : BigInt = BigInt (0 ), proof : => Seq [MptNode ] = Seq .empty[MptNode ]): StorageValueProof =
46
- new StorageValueProof (StorageProofKey (key), value, proof.map(asRlpSerializedNode))
46
+ def apply (position : BigInt , value : Option [BigInt ], proof : Option [Vector [MptNode ]]): StorageValueProof =
47
+ (value, proof) match {
48
+ case (Some (value), Some (proof)) => new StorageValueProof (key = StorageProofKey (position), value = value, proof = proof.map(asRlpSerializedNode))
49
+ case (None , Some (proof)) => new StorageValueProof (key = StorageProofKey (position), proof = proof.map(asRlpSerializedNode))
50
+ case (Some (value), None ) => new StorageValueProof (key = StorageProofKey (position), value = value)
51
+ case (None , None ) => new StorageValueProof (key = StorageProofKey (position))
52
+ }
53
+
54
+ def apply (position : BigInt ): StorageValueProof =
55
+ new StorageValueProof (key = StorageProofKey (position))
47
56
48
57
def asRlpSerializedNode (node : MptNode ): ByteString =
49
58
ByteString (MptTraversals .encodeNode(node))
0 commit comments