Skip to content

Commit 02aec76

Browse files
committed
Add a helper class for wallet related operations
1 parent c291e6c commit 02aec76

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

pxsol/wallet.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,28 @@
66
import typing
77

88

9+
class WalletHelper:
10+
# A helper class for wallet related operations.
11+
12+
@classmethod
13+
def requisition_send(
14+
cls,
15+
prikey: typing.List[pxsol.core.PriKey],
16+
rqlist: typing.List[pxsol.core.Requisition],
17+
) -> bytearray:
18+
# Sends a transaction built from the given requisitions and signed with the given private keys. This function
19+
# will wait until the transaction is confirmed. Returns the first signature of the transaction, also known as
20+
# the transaction id.
21+
tx = pxsol.core.Transaction.requisition_decode(prikey[0].pubkey(), rqlist)
22+
tx.message.recent_blockhash = pxsol.base58.decode(pxsol.rpc.get_latest_blockhash({})['blockhash'])
23+
tx.sign(prikey)
24+
assert len(tx.serialize()) <= 1232
25+
txid = pxsol.rpc.send_transaction(base64.b64encode(tx.serialize()).decode(), {})
26+
assert pxsol.base58.decode(txid) == tx.signatures[0]
27+
pxsol.rpc.wait([txid])
28+
return tx.signatures[0]
29+
30+
931
class WalletLoaderV3:
1032
# A built-in solana wallet that can be used to perform program loader v3 operations.
1133

0 commit comments

Comments
 (0)