Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending Transactions - working only once for newly created accounts #12

Open
allensh11 opened this issue Aug 25, 2019 · 13 comments
Open

Comments

@allensh11
Copy link
Contributor

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 allensh11 changed the title Sending Transactions Sending Transactions - working only once for newly created accounts Aug 25, 2019
@HubCodes
Copy link
Contributor

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

@allensh11
Copy link
Contributor Author

allensh11 commented Aug 26, 2019

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?

@HubCodes
Copy link
Contributor

HubCodes commented Aug 27, 2019

@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

@allensh11
Copy link
Contributor Author

allensh11 commented Aug 29, 2019

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?

@HubCodes
Copy link
Contributor

@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.

@sabgkang
Copy link

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

Could you please check it out?

@HubCodes
Copy link
Contributor

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

@sabgkang
Copy link

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

@sorawit
Copy link
Member

sorawit commented Sep 18, 2019

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

@allensh11
Copy link
Contributor Author

Hi @HubCodes - just wondering - is the above snippet you posted in #12 (comment) 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

@HubCodes
Copy link
Contributor

HubCodes commented Sep 25, 2019

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

@allensh11
Copy link
Contributor Author

Thanks for the reply @HubCodes

@allensh11
Copy link
Contributor Author

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants