Module: Ethereum::SPV

Defined in:
lib/ethereum/spv.rb,
lib/ethereum/spv/proof.rb,
lib/ethereum/spv/proof_verifier.rb,
lib/ethereum/spv/proof_constructor.rb

Defined Under Namespace

Classes: Proof, ProofConstructor, ProofVerifier

Class Method Summary collapse

Class Method Details

.grabbing(node) ⇒ Object



20
21
22
# File 'lib/ethereum/spv.rb', line 20

def grabbing(node)
  proof.grabbing node if proof
end

.make_transaction_proof(block, tx) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/ethereum/spv.rb', line 55

def make_transaction_proof(block, tx)
  result, nodes = record do
    block.apply_transaction(tx)
  end

  nodes
    .map {|x| RLP.encode(x) }
    .uniq
    .map {|x| RLP.decode(x) }
end

.modeObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/ethereum/spv.rb', line 44

def mode
  case proof
  when ProofConstructor
    :record
  when ProofVerifier
    :verify
  else
    nil
  end
end

.proofObject



16
17
18
# File 'lib/ethereum/spv.rb', line 16

def proof
  proofs.last
end

.proofsObject



12
13
14
# File 'lib/ethereum/spv.rb', line 12

def proofs
  @proofs ||= []
end

.recordObject



28
29
30
31
32
33
34
35
# File 'lib/ethereum/spv.rb', line 28

def record
  proofs.push ProofConstructor.new
  result = yield
  nodes = proof.decoded_nodes
  [result, nodes]
ensure
  proofs.pop
end

.store(node) ⇒ Object



24
25
26
# File 'lib/ethereum/spv.rb', line 24

def store(node)
  proof.store node if proof
end

.verify(nodes) ⇒ Object



37
38
39
40
41
42
# File 'lib/ethereum/spv.rb', line 37

def verify(nodes)
  proofs.push ProofVerifier.new(nodes: nodes)
  yield
ensure
  proofs.pop
end

.verify_transaction_proof(block, tx, nodes) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/ethereum/spv.rb', line 66

def verify_transaction_proof(block, tx, nodes)
  verify do
    block.apply_transaction(tx)
  end
  true
rescue
  puts $!
  false
end