def quicktx(client, gasprice, startgas, to, value, data, key): """Create and finalize a transaction. This command is a shortcut that chains getnonce, mktx, signtx, and applytx. It returns the server's response. """ encoded_key = encode_privkey(key, 'hex') nonce = int(client.getaccount(utils.privtoaddr(encoded_key))['nonce']) tx = Transaction(nonce, gasprice, startgas, to, value, str(data)) tx.sign(encode_privkey(key, 'hex')) pecho(client.applytx(tx))
tx = Transaction( 5, 2, '54450450e24286143a35686ad77a7c851ada01a0', 2, '2001:db8::1/16', [ 1, '1.1.1.1', '54dbb737eac5007103e729e9ab7ce64a6850a310', 2, '2001:cdba::3257:9652', '89b44e4d3c81ede05d0f5de8d1a68f754d73d997', 1, '3.3.3.3', '3a1e02d9ea25349c47fe2e94f4265cd261c5c7ca' ]) # Category 3 '''tx = Transaction(5,3,'54450450e24286143a35686ad77a7c851ada01a0', 1, '192.152.0.0/16', [2, '2001:cdba:9abc:5678::', 20, 230, 1, '5.5.5.5', 45, 50])''' '''tx = Transaction(5,3,'54450450e24286143a35686ad77a7c851ada01a0', 2, '2001:db8::1/16', [2, '2001:cdba:9abc:5678::', 20, 230])''' tx.sign(key) print "Tx ID", tx.hash.encode('hex') print tx.ip_network #print utils.ip_to_bytes('192.152.0.0/16').encode('hex') assert tx.sender == addr print "Tx Sender OK" assert tx.v in (27, 28) print "V OK" #print tx.metadata print tx.to_dict() rawtx = rlp.encode(tx).encode('hex') print '\n', rawtx, '\n' tx2 = rlp.decode(rawtx.decode('hex'), Transaction) #print tx2.sender.encode('hex') print tx2.to_dict() assert rlp.encode(tx).encode('hex') == rlp.encode(tx2).encode('hex')
import sys db = LevelDB("./chain") env = Env(db) #env = Env(_EphemDB()) add1 = "094a2c9f5b46416b9b9bd9f1efa1f3a73d46cec2" add2 = "7719818983cb546d1badee634621dad4214cba25" add3 = "a3e04410f475b813c01ca77ff12cb277991e62d2" ks1 = Keystore.load("./keystore/094a2c9f5b46416b9b9bd9f1efa1f3a73d46cec2","TFG1234") ks2 = Keystore.load("./keystore/7719818983cb546d1badee634621dad4214cba25","TFG1234") ks3 = Keystore.load("./keystore/a3e04410f475b813c01ca77ff12cb277991e62d2","TFG1234") tx1 = Transaction(1, 0, add2, 1, '192.152.0.0/12') tx1.sign(ks1.privkey) tx8 = Transaction(0, 0, add2, 2, '2001:cdba::3257:9652') tx8.sign(ks1.privkey) tx2 = Transaction(0, 0, add3, 1, '192.152.0.0/16') tx2.sign(ks2.privkey) tx3 = Transaction(0, 1, add1, 1, '192.152.0.0/24') tx3.sign(ks3.privkey) tx4 = Transaction(1, 1, add2, 1, '192.152.0.0/25') tx4.sign(ks3.privkey) tx5 = Transaction(2, 0, add1, 1, '192.152.0.0/26') tx5.sign(ks3.privkey) tx6 = Transaction(3, 3, add3, 1, '192.152.0.0/16',[2, '2001:cdba:9abc:5678::', 20, 230,1, '5.5.5.5', 45, 50]) tx6.sign(ks3.privkey) tx7 = Transaction(1, 2, add3, 1, '192.152.0.0/16',[1, '1.1.1.2', '54dbb737eac5007103e729e9ab7ce64a6850a310',
print "Adding some Delegated IP TXs" print(chain.get_own_ips(add1)) ip4List = list(IPNetwork('192.168.2.0/30')) ip6List = list(IPNetwork('2001:db9:0:1:1:1:1:1/126')) nonce = 0 while i < len(ip4List): if (blockNum % 2 == 0): tx = Transaction(nonce, 1, add2, 1, str(ip4List[i]), time=int(time.time())) tx.sign(ks1.privkey) chain.add_pending_transaction(tx) i += 1 else: tx = Transaction(nonce, 1, add2, 2, str(ip6List[i]), time=int(time.time())) tx.sign(ks1.privkey) chain.add_pending_transaction(tx) block = chain.create_block(add1) block.sign(ks1.privkey) chain.add_block(block) nonce += 1
NUM_TX = 5 NUM_BLOCKS = 100 db = LevelDB("./chain") env = Env(db) chain = ChainService(env) block_creation = [] block_addition = [] for NUM_TX in range(0, 250, 10): for j in range(NUM_BLOCKS*2): time.sleep(1) if j%2 != 0: for i in range(1,min(NUM_TX,len(addresses)-1)+1): ipset = chain.get_own_ips(addresses[i]) nonce = chain.chain.state.get_nonce(addresses[i]) tx = Transaction(nonce, 0, addresses[i-1], 1, ipset.iter_cidrs()[0].ip, time=int(time.time())) tx.sign(keys[i].privkey) chain.validate_transaction(tx) chain.add_pending_transaction(tx) c1 = datetime.datetime.now() block = chain.create_block(addresses[0]) block.sign(keys[0].privkey) c2 = datetime.datetime.now() c3 = c2-c1 block_creation.append(c3.total_seconds()) print(sys.getsizeof(block)) c1 = datetime.datetime.now() chain.add_block(block) c2 = datetime.datetime.now() c3 = c2-c1 block_addition.append(c3.total_seconds())