pylibra icon indicating copy to clipboard operation
pylibra copied to clipboard

Sending Transactions - working only once for newly created accounts

Open allensh11 opened this issue 5 years ago • 13 comments

I'm running into strange behaviour with transactions. Seems like I can create a transaction for newly created accounts but then I can't send any further transactions afterwards, regardless of whether the first transaction was successfull or not. As far as I can tell, I am following the steps documented in the readme.

Does anyone know what could possibly be causing this?

allensh11 avatar Aug 25 '19 12:08 allensh11

Looking for #9, I think It may help you. :) Sadly, It seems like It's not applied to PyPI.

HubCodes avatar Aug 26 '19 08:08 HubCodes

Thanks @HubCodes I saw you had something similar in #10 and proposed a fix. I got your fix and referenced my fork in my requirements.txt (git+git://github.com/jnsead/pylibra.git@master#egg=pylibra). That way I could get the updated code for pylibra in my project and not rely on PyPi.

However - the issue with the transfers appears to still be happening.. Were you able to resolve it somehow?

allensh11 avatar Aug 26 '19 13:08 allensh11

@jnsead Umm... I used following python code to know how libra api works. I hope it can help you.

from pylibra import LibraClient, LibraWallet
from pylibra.proto.transaction_pb2 import TransactionArgument
from pylibra.transaction import CustomTransaction, TransferTransaction
from pylibra.proto.admission_control_pb2 import SubmitTransactionRequest
from pylibra.proto.transaction_pb2 import SignedTransaction
from pylibra.proto.transaction_pb2 import RawTransaction
from sha3 import sha3_256
import time

tx_script = '4c49425241564d0a010007014a00000004000000034e000000060000000c54000000060000000d5a0000000600000005600000002900000004890000002000000007a90000000e00000000000001000200010300020002040200030003020402063c53454c463e0c4c696272614163636f756e74046d61696e0f7061795f66726f6d5f73656e64657200000000000000000000000000000000000000000000000000000000000000000001020104000c000c0111010002'

wallet = LibraWallet()
account1 = wallet.get_account(1)
account2 = wallet.get_account(2)
client = LibraClient()

client.mint_with_faucet(account1, 10000000)

print(f'Account1 address: {account1.address}')
print(f'Account1 private key: {account1.private_key}')
print(f'Account2 address: {account2.address}')
print(f'Account2 private key: {account2.private_key}')

address1 = account1.address
address2 = account2.address

sequence_number = 0  # FIXME: Change it repeatedly

raw_tx = RawTransaction()
raw_tx.sender_account = bytes.fromhex(address1)
raw_tx.sequence_number = sequence_number
raw_tx.max_gas_amount = 100000
raw_tx.gas_unit_price = 1
raw_tx.expiration_time = int(time.time()) + 10
raw_tx.program.code = bytes.fromhex(tx_script)
arg1 = raw_tx.program.arguments.add()
arg1.type = TransactionArgument.ADDRESS
arg1.data = bytes.fromhex(address2)
arg2 = raw_tx.program.arguments.add()
arg2.type = TransactionArgument.U64
arg2.data = (1000).to_bytes(8, 'little') # Send 0.001 lib

tx = raw_tx.SerializeToString()

request = SubmitTransactionRequest()
signed_tx = request.signed_txn
signed_tx.raw_txn_bytes = tx
signed_tx.sender_public_key = bytes.fromhex(account1.public_key)
hashfn = sha3_256()
hashfn.update(
    bytes.fromhex('46f174df6ca8de5ad29745f91584bb913e7df8dd162e3e921a5c1d8637c88d16'))
hashfn.update(tx)
signature = account1.sign(hashfn.digest())[:64]
signed_tx.sender_signature = signature

result = client.stub.SubmitTransaction(request)

print(result)

And I found Its result in libexplorer: https://libexplorer.com/version/14103

HubCodes avatar Aug 27 '19 01:08 HubCodes

Thanks for that! I have a question please... I can see your 2 accounts originate from a newly created wallet. Do you know if the code works for existing accounts from 2 different wallets?

Also could you please explain a bit more about the tx_script variable? What is it and where did it come from?

allensh11 avatar Aug 29 '19 12:08 allensh11

@jnsead

(1) Actually, If you have a private key, you can send transactions without regard to a wallet. (2) tx_script came from libra source code (I compiled it with libra mvir compiler) + (2.5) It can check at pylibra's TransferTransaction class.

HubCodes avatar Aug 29 '19 13:08 HubCodes

@HubCodes I ran your code and get the result as below, vm_status { validation { code: UnknownScript message: "none" } }

Could you please check it out?

sabgkang avatar Sep 17 '19 05:09 sabgkang

@sabgkang Libra testnet evolves very fast. I don't know what happened, but I think there are compiler or/and language changes.

HubCodes avatar Sep 17 '19 06:09 HubCodes

@HubCodes Thank you for the prompt reply. Indeed, Libra evolves too fast.

sabgkang avatar Sep 17 '19 13:09 sabgkang

Sorry guys we have been very busy with Band Protocol IEO launch. I will get back on all these issues asap.

sorawit avatar Sep 18 '19 04:09 sorawit

Hi @HubCodes - just wondering - is the above snippet you posted in https://github.com/bandprotocol/pylibra/issues/12#issuecomment-526176538 still working for you? If not, do you or anyone else know what's changed? I'm trying to figure out how and what needs updating but running into a few issues

allensh11 avatar Sep 25 '19 03:09 allensh11

@jnsead Hi, I'm not following latest libra changes, so I don't know what happened. Sorry :(

HubCodes avatar Sep 25 '19 07:09 HubCodes

Thanks for the reply @HubCodes

allensh11 avatar Sep 25 '19 12:09 allensh11

@sorawit - do you have any ideas on this? It appears there have been changes earlier this month (https://community.libra.org/t/testnet-update-september-4th/1630). I'm not familiar with Rust - was wondering if you'd be able to help out?

allensh11 avatar Sep 25 '19 12:09 allensh11