def gen_transaction(recipients_lst: list, priv_key: bytes, amount_lst: list, fee: int, sequence: int, account_num: int, gas: int = 999999, memo: str = "", chain_id_: str = chain_id, denom: str = denomination): tx = Transaction( privkey=priv_key, account_num=account_num, sequence=sequence, fee=fee, gas=gas, memo=memo, chain_id=chain_id_, sync_mode="sync", ) if len(recipients_lst) != len(amount_lst): raise Exception( "ERROR: recipients_lst and amount_lst lengths not equal") # print(f'Got {len(recipients_lst)} recipients') for i, addr in enumerate(recipients_lst): # print(f'{i+1}\\{len(recipients_lst)} {addr} amount: {amount_lst[i]} {denomination}') tx.add_transfer(recipient=recipients_lst[i], amount=amount_lst[i], denom=denom) return tx
def test_sign(): private_key = bytes.fromhex( "2afc5a66b30e7521d553ec8e6f7244f906df97477248c30c103d7b3f2c671fef") unordered_sign_message = { "chain_id": "tendermint_test", "account_number": "1", "fee": { "gas": "21906", "amount": [{ "amount": "0", "denom": "" }] }, "memo": "", "sequence": "0", "msgs": [{ "type": "cosmos-sdk/Send", "value": { "inputs": [{ "address": "cosmos1qperwt9wrnkg5k9e5gzfgjppzpqhyav5j24d66", "coins": [{ "amount": "1", "denom": "STAKE" }], }], "outputs": [{ "address": "cosmos1yeckxz7tapz34kjwnjxvmxzurerquhtrmxmuxt", "coins": [{ "amount": "1", "denom": "STAKE" }], }], }, }], } dummy_num = 1337 tx = Transaction( privkey=private_key, account_num=dummy_num, sequence=dummy_num, fee=dummy_num, gas=dummy_num, ) tx._get_sign_message = Mock( return_value=unordered_sign_message) # type: ignore expected_signature = ( "YjJhlAf7aCnUtLyBNDp9e6LKuNgV7hJC3rmm0Wro5nBsIPVtWzjuobsp/AhR5Kht+HcRF2zBq4AfoNQMIbY6fw==" ) actual_signature = tx._sign() assert actual_signature == expected_signature
def test_get_pushable_tx(): expected_pushable_tx = '{"tx":{"msg":[{"type":"cosmos-sdk/MsgSend","value":{"from_address":"cosmos1lgharzgds89lpshr7q8kcmd2esnxkfpwvuz5tr","to_address":"cosmos103l758ps7403sd9c0y8j6hrfw4xyl70j4mmwkf","amount":[{"denom":"uatom","amount":"387000"}]}}],"fee":{"gas":"37000","amount":[{"denom":"uatom","amount":"1000"}]},"memo":"","signatures":[{"signature":"chbQMmrg18ZQSt3q3HzW8S8pMyGs/TP/WIbbCyKFd5IiReUY/xJB2yRDEtF92yYBjxEU02z9JNE7VCQmmxWdQw==","pub_key":{"type":"tendermint/PubKeySecp256k1","value":"A49sjCd3Eul+ZXyof7qO460UaO73otrmySHyTNSLW+Xn"},"account_number":"11335","sequence":"0"}]},"mode":"sync"}' # noqa: E501 _tx_total_cost = 388000 fee = 1000 amount = _tx_total_cost - fee tx = Transaction( privkey=bytes.fromhex( "26d167d549a4b2b66f766b0d3f2bdbe1cd92708818c338ff453abde316a2bd59" ), account_num=11335, sequence=0, fee=fee, gas=37000, chain_id="cosmoshub-2", ) tx.add_transfer(recipient="cosmos103l758ps7403sd9c0y8j6hrfw4xyl70j4mmwkf", amount=amount) pushable_tx = tx.get_pushable() assert pushable_tx == expected_pushable_tx
async def gen_transaction(recipient_: str, sequence: int, denom: list, account_num: int, amount_: list, gas: int = GAS_LIMIT, memo: str = "", chain_id_: str = CHAIN_ID, fee: int = GAS_PRICE, priv_key: str = FAUCET_PRIVKEY): tx = Transaction(privkey=bytes.fromhex(priv_key), account_num=account_num, sequence=sequence, fee_denom=MAIN_DENOM, fee=fee, gas=gas, memo=memo, chain_id=chain_id_, hrp=BECH32_HRP, sync_mode="sync") if type(denom) is list: for i, den in enumerate(denom): tx.add_transfer(recipient=recipient_, amount=amount_[i], denom=den) else: tx.add_transfer(recipient=recipient_, amount=amount_[0], denom=denom[0]) return tx
print("host " + host) print("privkey " + privkey) diffList = [] fd = open("./diffs/diff_" + privkey + ".txt", "w") i = 0 #for i in range(10000): while i < 100000: print("count", i) print("trigger time", datetime.datetime.now()) tx = Transaction(privkey=privkey, account_num=account_num, sequence=i, fee=5000, fee_denom='ucosm', gas=200000, memo="", chain_id="testnet", sync_mode="async") amount = (i + 1) % 100 + 1 try: tx.add_transfer( recipient="cosmos19t5wd4u9euv2etjgcqtjf3gg5v76j0m8rse8w8", amount=amount, denom='ucosm') pushable_tx = tx.get_pushable() #print(pushable_tx) headers = {'Content-Type': 'application/json; charset=utf-8'} startTime = datetime.datetime.now().timestamp() res = requests.post(host, headers=headers, data=pushable_tx)
host="http://" + sys.argv[1] + ":1317/txs" privkey=sys.argv[2] account_num=sys.argv[3] recipient="friday12e4px0gq573726l4rcey2cne0dvsfypc78veyc" print("host " + host) print("privkey " + privkey) i=0 #for i in range(10000): while i < 1000000: print("count", i) tx = Transaction( privkey=privkey, account_num=account_num, sequence=i, fee=1000, gas=70000, memo="", chain_id="testnet", sync_mode="async" ) amount = (i+1)%100 + 1 try: tx.add_transfer(recipient=recipient, amount=amount) pushable_tx=tx.get_pushable() print(pushable_tx) headers = {'Content-Type': 'application/json; charset=utf-8'} res=requests.post(host, headers=headers, data=pushable_tx) #res=requests.post(host, data=pushable_tx) print(res.status_code) print(res.text) if not "code" in res.text:
int( float(parseComissionFromValidator["result"]["val_commission"][0] ["amount"])), 'pot': int(commonPot) } with open('commission.txt', 'w') as outfile: json.dump(commissionAmount, outfile) if amountToSend > 0: tx = Transaction( privkey=privkey, account_num=accountNumber, sequence=sequenceDefault, fee=50000, gas=200000, memo="lottery-chimere.io", chain_id="secret-2", sync_mode="sync", ) tx.add_transfer(recipient=delegators[sort]['address'], amount=amountToSend) tx_broadcast = tx.get_pushable() print(tx_broadcast) url = "https://api.secretapi.io/txs" x = requests.post(url, data=tx_broadcast) print(x.text) url_chimere = f"https://chimere.io/api/lottery-pot-update/{env['apikeychimere']}" y = requests.post(url_chimere,