示例#1
0
 def fromJSON(json: Dict[str, Dict[str, Any]]) -> Any:
     result = Transactions()
     for tx in json:
         if json[tx]["descendant"] == "Claim":
             result.add(Claim.fromJSON(json[tx]))
         elif json[tx]["descendant"] == "Send":
             result.add(Send.fromJSON(json[tx]))
         elif json[tx]["descendant"] == "Data":
             result.add(Data.fromJSON(json[tx]))
         else:
             raise Exception("JSON has an unsupported Transaction type: " +
                             json[tx]["descendant"])
     return result
示例#2
0
def HundredFortySevenTest(rpc: RPC) -> None:
    file: IO[Any] = open("e2e/Vectors/Transactions/ClaimedMint.json", "r")
    vectors: Dict[str, Any] = json.loads(file.read())
    file.close()

    #Merit.
    merit: Merit = Merit.fromJSON(vectors["blockchain"])
    #Transactions.
    transactions: Transactions = Transactions.fromJSON(vectors["transactions"])

    #Ed25519 keys.
    privKey: ed25519.SigningKey = ed25519.SigningKey(b'\0' * 32)
    pubKey: ed25519.VerifyingKey = privKey.get_verifying_key()

    #Grab the Claim hash,
    claim: bytes = merit.blockchain.blocks[-1].body.packets[0].hash

    #Create a Send which underflows.
    send: Send = Send(
        [(claim, 0)],
        [(pubKey.to_bytes(), 18446744073709551231),
         (pubKey.to_bytes(),
          385 + Claim.fromTransaction(transactions.txs[claim]).amount)])
    send.sign(privKey)
    send.beat(SpamFilter(3))

    #Custom function to send the last Block and verify it errors at the right place.
    def checkFail() -> None:
        #Send the Send.
        rpc.meros.liveTransaction(send)

        #Handle sync requests.
        while True:
            #Try receiving from the Live socket, where Meros sends keep-alives.
            try:
                if len(rpc.meros.live.recv()) != 0:
                    raise Exception()
            except TestError:
                raise SuccessError(
                    "Node disconnected us after we sent an invalid Transaction."
                )
            except Exception:
                raise TestError("Meros sent a keep-alive.")

    #Create and execute a Liver.
    Liver(rpc, vectors["blockchain"], transactions, callbacks={
        12: checkFail
    }).live()
示例#3
0
transactions.add(claim)
merit.add(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   packets=[VerificationPacket(claim.hash,
                                               [0])]).finish(0, merit))

#Give the second key pair Merit.
merit.add(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   minerID=PrivateKey(1)).finish(0, merit))

#Create two competing Sends.
packets: List[VerificationPacket] = []
for i in range(2):
    send: Send = Send(
        [(claim.hash, 0)],
        [(edPubKeys[i].to_bytes(),
          Claim.fromTransaction(transactions.txs[claim.hash]).amount)])
    send.sign(edPrivKey)
    send.beat(sendFilter)
    transactions.add(send)

    packets.append(VerificationPacket(send.hash, [i]))

#Archive the Packets and close the Epoch.
merit.add(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   packets=packets,
                   minerID=0).finish(0, merit))
#As far as I can tell, this should be range(5).
#That said, I rather have an extra Block than change the generated vector.
#A semantic JSON diff checker can be used to verify moving to 5 is fine, as long as the output is eyed over.
示例#4
0
edPrivKey: ed25519.SigningKey = ed25519.SigningKey(b'\0' * 32)
edPubKey: ed25519.VerifyingKey = edPrivKey.get_verifying_key()

#Create the Claim.
claim: Claim = Claim([(merit.mints[-1].hash, 0)], edPubKeys[0].to_bytes())
claim.amount = merit.mints[-1].outputs[0][1]
claim.sign(PrivateKey(0))
transactions.add(claim)
merit.add(
    PrototypeBlock(merit.blockchain.blocks[-1].header.time + 1200,
                   packets=[VerificationPacket(claim.hash,
                                               [0])]).finish(0, merit))

#Create 12 Sends.
sends: List[Send] = []
sends.append(Send([(claim.hash, 0)], [(edPubKey.to_bytes(), claim.amount)]))
for _ in range(12):
    sends[-1].sign(edPrivKey)
    sends[-1].beat(sendFilter)
    transactions.add(sends[-1])

    sends.append(
        Send([(sends[-1].hash, 0)],
             [(edPubKey.to_bytes(), sends[-1].outputs[0][1])]))

#Order to verify the Transactions in.
#Dict key is holder nick.
#Dict value is list of transactions.
#Tuple's second value is miner.
orders: List[Tuple[Dict[int, List[int]], Union[PrivateKey, int]]] = [
    #Verify the first two Merit Holders.
示例#5
0
文件: SISend.py 项目: Vyryn/Meros
edPrivKey: Ristretto.SigningKey = Ristretto.SigningKey(b'\0' * 32)
edPubKey: bytes = edPrivKey.get_verifying_key()

claim: Claim = Claim([(merit.mints[-1], 0)], edPubKey)
claim.sign(PrivateKey(0))
transactions.add(claim)
merit.add(
  PrototypeBlock(
    merit.blockchain.blocks[-1].header.time + 1200,
    packets=[VerificationPacket(claim.hash, [0])]
  ).finish(0, merit)
)

#Create a Send spending it twice.
send: Send = Send(
  [(claim.hash, 0), (claim.hash, 0)],
  [(edPubKey, Claim.fromTransaction(transactions.txs[claim.hash]).amount * 2)]
)
send.sign(edPrivKey)
send.beat(sendFilter)
transactions.add(send)

merit.blockchain.add(
  PrototypeBlock(
    merit.blockchain.blocks[-1].header.time + 1200,
    [VerificationPacket(send.hash, [0])]
  ).finish(0, merit)
)

with open("e2e/Vectors/Transactions/SameInput/Send.json", "w") as vectors:
  vectors.write(json.dumps({
    "blockchain": merit.blockchain.toJSON(),
示例#6
0
文件: Fifty.py 项目: vporton/Meros
blsPrivKeys: List[PrivateKey] = [
    PrivateKey(blake2b(b'\0', digest_size=32).digest()),
    PrivateKey(blake2b(b'\1', digest_size=32).digest())
]
blsPubKeys: List[PublicKey] = [
    blsPrivKeys[0].toPublicKey(), blsPrivKeys[1].toPublicKey()
]

#Grab the Claim hash.
claim: bytes = blockchain.blocks[-1].body.packets[0].hash

#Create 12 Sends.
sends: List[Send] = []
sends.append(
    Send([(claim, 0)],
         [(edPubKey.to_bytes(), Claim.fromTransaction(
             transactions.txs[claim]).amount)]))
for _ in range(12):
    sends[-1].sign(edPrivKey)
    sends[-1].beat(sendFilter)
    transactions.add(sends[-1])

    sends.append(
        Send([(sends[-1].hash, 0)],
             [(edPubKey.to_bytes(), sends[-1].outputs[0][1])]))

#Order to verify the Transactions in.
#Dict key is holder nick.
#Dict value is list of transactions.
#Tuple's second value is miner.
orders: List[Tuple[Dict[int, List[int]], Union[bytes, int]]] = [
示例#7
0
#Ed25519 keys.
edPrivKey: ed25519.SigningKey = ed25519.SigningKey(b'\0' * 32)
edPubKey: ed25519.VerifyingKey = edPrivKey.get_verifying_key()

#BLS keys.
blsPrivKey: PrivateKey = PrivateKey(blake2b(b'\0', digest_size=32).digest())
blsPubKey: PublicKey = blsPrivKey.toPublicKey()

#Grab the Claim hash.
claim: bytes = blockchain.blocks[-1].body.packets[0].hash

#Create a Send spending it twice.
send: Send = Send(
  [(claim, 0), (claim, 0)],
  [(
    edPubKey.to_bytes(),
    Claim.fromTransaction(transactions.txs[claim]).amount * 2
  )]
)
send.sign(edPrivKey)
send.beat(sendFilter)
transactions.add(send)

#Create a Verification/VerificationPacket for the Send.
sv: SignedVerification = SignedVerification(send.hash)
sv.sign(0, blsPrivKey)
packet: VerificationPacket = VerificationPacket(send.hash, [0])

#Add a Block verifying it.
block: Block = Block(
  BlockHeader(