2020-01-15 13:56:50 +00:00
package trie
2020-03-25 15:40:30 +00:00
import "errors"
2020-03-23 22:10:36 +00:00
func ( t * Trie ) ExtractWitness ( blockNr uint64 , trace bool , rs * ResolveSet ) ( * Witness , error ) {
2020-04-08 12:59:30 +00:00
var h HashOnly
if rs != nil {
h = rs
}
return extractWitnessFromRootNode ( t . root , blockNr , trace , h )
2020-01-24 10:58:01 +00:00
}
2020-03-25 15:40:30 +00:00
func ( t * Trie ) ExtractWitnessForPrefix ( prefix [ ] byte , blockNr uint64 , trace bool , rs * ResolveSet ) ( * Witness , error ) {
node , _ , found := t . getNode ( prefix , false )
if ! found {
return nil , errors . New ( "no data found for given prefix" )
}
return extractWitnessFromRootNode ( node , blockNr , trace , rs )
}
2020-01-24 10:58:01 +00:00
// extractWitnessFromRootNode extracts a witness for a subtrie starting from the specified root
// if hashOnly param is nil it will make a witness for the full subtrie,
// if hashOnly param is set to a ResolveSet instance, it will make a witness for only the accounts/storages that were actually touched; other paths will be hashed.
2020-03-23 22:10:36 +00:00
func extractWitnessFromRootNode ( root node , blockNr uint64 , trace bool , hashOnly HashOnly ) ( * Witness , error ) {
builder := NewWitnessBuilder ( root , blockNr , trace )
2020-04-08 12:59:30 +00:00
var limiter * MerklePathLimiter = nil
2020-01-24 10:58:01 +00:00
if hashOnly != nil {
hr := newHasher ( false )
defer returnHasherToPool ( hr )
limiter = & MerklePathLimiter { hashOnly , hr . hash }
}
return builder . Build ( limiter )
2020-01-15 13:56:50 +00:00
}