75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
from collections import OrderedDict
|
|
from typing import MutableMapping
|
|
|
|
import nacl.signing
|
|
|
|
from rainbowadn.chain.reduction.reductionchainmetafactory import ReductionChainMetaFactory
|
|
from rainbowadn.hashing.hashmentionable import HashMentionable
|
|
from rainbowadn.hashing.hashpoint import HashPoint
|
|
from rainbowadn.hashing.hashresolver import HashResolver
|
|
from rainbowadn.hashing.nullability.notnull import NotNull
|
|
from rainbowadn.hashing.recursivementionable import RecursiveMentionable
|
|
from rainbowadn.v13.algo import MINT_CONST
|
|
from rainbowadn.v13.bankchain import BankChain
|
|
from rainbowadn.v13.subject import Subject
|
|
from rainbowadn.v13.transaction import CoinData, Transaction
|
|
|
|
|
|
class DumbResolver(HashResolver):
|
|
def __init__(self):
|
|
self.table: MutableMapping[bytes, bytes] = OrderedDict()
|
|
|
|
def _resolve(self, point: bytes) -> bytes:
|
|
assert isinstance(point, bytes)
|
|
return self.table[point]
|
|
|
|
def save(self, hash_point: HashPoint) -> None:
|
|
assert isinstance(hash_point, HashPoint)
|
|
if hash_point.point in self.table:
|
|
pass
|
|
elif isinstance(hash_point.value, NotNull):
|
|
value: HashMentionable = hash_point.value.value
|
|
self.table[hash_point.point] = HashPoint.bytes_of_mentioned(value)
|
|
if isinstance(value, RecursiveMentionable):
|
|
for hash_point in value.points():
|
|
self.save(hash_point)
|
|
else:
|
|
raise TypeError
|
|
|
|
|
|
def main():
|
|
dr = DumbResolver()
|
|
bank = BankChain.empty(ReductionChainMetaFactory(), dr)
|
|
key_0 = nacl.signing.SigningKey.generate()
|
|
transaction_0 = Transaction.make(
|
|
[],
|
|
[CoinData.of(Subject(key_0.verify_key), 1_000_000)],
|
|
[]
|
|
)
|
|
coin_0, coin_1 = transaction_0.coins(dr, MINT_CONST, NotNull(HashPoint.of(Subject(key_0.verify_key))))
|
|
bank = bank.adds(
|
|
[
|
|
transaction_0,
|
|
Transaction.make(
|
|
[coin_1],
|
|
[CoinData.of(Subject(nacl.signing.SigningKey.generate().verify_key), 10_000)],
|
|
[key_0]
|
|
),
|
|
]
|
|
)
|
|
bank = bank.adds(
|
|
[]
|
|
)
|
|
print(bank)
|
|
print(bank.verify())
|
|
dr.save(HashPoint.of(bank.reference))
|
|
bank = BankChain.from_reference(ReductionChainMetaFactory(), dr.resolve(HashPoint.of(bank.reference).loose()), dr)
|
|
print(bank)
|
|
print(bank.verify())
|
|
for key, value in dr.table.items():
|
|
print(key.hex(), value.hex())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|