Resubmit Python2 updates

This commit is contained in:
ddawson
2023-09-05 13:58:05 -07:00
parent 3de3aa68f0
commit 757bfd4c07
17 changed files with 1406 additions and 352 deletions

View File

@@ -1,22 +1,19 @@
import xrpl
import json
import xrpl.clients
import xrpl.wallet
testnet_url = "https://s.altnet.rippletest.net:51234/"
def get_account(seed):
"""get_account"""
JSON_RPC_URL = "https://s.altnet.rippletest.net:51234/"
client = xrpl.clients.JsonRpcClient(JSON_RPC_URL)
client = xrpl.clients.JsonRpcClient(testnet_url)
if (seed == ''):
new_wallet = xrpl.wallet.generate_faucet_wallet(client)
else:
new_wallet = xrpl.wallet.Wallet(seed, sequence = 79396029)
return(new_wallet)
new_wallet = xrpl.wallet.Wallet.from_seed(seed)
return new_wallet
def get_account_info(accountId):
"""get_account_info"""
JSON_RPC_URL = 'wss://s.altnet.rippletest.net:51234'
client = xrpl.clients.JsonRpcClient(JSON_RPC_URL)
client = xrpl.clients.JsonRpcClient(testnet_url)
acct_info = xrpl.models.requests.account_info.AccountInfo(
account=accountId,
ledger_index="validated"
@@ -25,20 +22,15 @@ def get_account_info(accountId):
return response.result['account_data']
def send_xrp(seed, amount, destination):
sending_wallet = xrpl.wallet.Wallet(seed, sequence = 16237283)
testnet_url = "https://s.altnet.rippletest.net:51234"
sending_wallet = xrpl.wallet.Wallet.from_seed(seed)
client = xrpl.clients.JsonRpcClient(testnet_url)
payment = xrpl.models.transactions.Payment(
account=sending_wallet.classic_address,
account=sending_wallet.address,
amount=xrpl.utils.xrp_to_drops(int(amount)),
destination=destination,
)
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
payment, sending_wallet, client)
try:
tx_response = xrpl.transaction.send_reliable_submission(signed_tx,client)
response = tx_response
except xrpl.transaction.XRPLReliableSubmissionException as e:
try:
response = xrpl.transaction.submit_and_wait(payment, client, sending_wallet)
except xrpl.transaction.XRPLReliableSubmissionException as e:
response = f"Submit failed: {e}"
return response

View File

@@ -1,8 +1,6 @@
import xrpl
import json
from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
from xrpl.models.requests.account_info import AccountInfo
testnet_url = "https://s.altnet.rippletest.net:51234"
@@ -14,28 +12,21 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
def create_trust_line(seed, issuer, currency, amount):
"""create_trust_line"""
# Get the client
receiving_wallet = Wallet(seed, sequence = 16237283)
receiving_wallet = Wallet.from_seed(seed)
client = JsonRpcClient(testnet_url)
# Define the trust line transaction
trustline_tx=xrpl.models.transactions.TrustSet(
account=receiving_wallet.classic_address,
account=receiving_wallet.address,
limit_amount=xrpl.models.amounts.IssuedCurrencyAmount(
currency=currency,
issuer=issuer,
value=int(amount)
)
)
# Sign and fill the transaction
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
trustline_tx, receiving_wallet, client)
# Submit the transaction and get results
reply = ""
try:
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
reply = response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply = f"Submit failed: {e}"
return reply
response = xrpl.transaction.submit_and_wait(trustline_tx,
client, receiving_wallet)
return response.result
#################
# send_currency #
@@ -44,29 +35,20 @@ def create_trust_line(seed, issuer, currency, amount):
def send_currency(seed, destination, currency, amount):
"""send_currency"""
# Get the client
sending_wallet=Wallet(seed, sequence=16237283)
sending_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
# Define the payment transaction.
send_currency_tx=xrpl.models.transactions.Payment(
account=sending_wallet.classic_address,
account=sending_wallet.address,
amount=xrpl.models.amounts.IssuedCurrencyAmount(
currency=currency,
value=int(amount),
issuer=sending_wallet.classic_address
issuer=sending_wallet.address
),
destination=destination
)
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
send_currency_tx, sending_wallet, client)
# Submit the transaction and get results
reply = ""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
reply = response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply = f"Submit failed: {e}"
return reply
response=xrpl.transaction.submit_and_wait(send_currency_tx, client, sending_wallet)
return response.result
###############
# get_balance #
@@ -74,8 +56,7 @@ def send_currency(seed, destination, currency, amount):
def get_balance(sb_account_id, op_account_id):
"""get_balance"""
JSON_RPC_URL='wss://s.altnet.rippletest.net:51234'
client=JsonRpcClient(JSON_RPC_URL)
client=JsonRpcClient(testnet_url)
balance=xrpl.models.requests.GatewayBalances(
account=sb_account_id,
ledger_index="validated",
@@ -91,29 +72,18 @@ def get_balance(sb_account_id, op_account_id):
def configure_account(seed, default_setting):
"""configure_account"""
# Get the client
wallet=Wallet(seed, sequence = 16237283)
wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
# Create transaction
if (default_setting):
setting_tx=xrpl.models.transactions.AccountSet(
account=wallet.classic_address,
set_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE
set_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_DEFAULT_RIPPLE
)
else:
setting_tx=xrpl.models.transactions.AccountSet(
account=wallet.classic_address,
clear_flag=xrpl.models.transactions.AccountSetFlag.ASF_DEFAULT_RIPPLE
clear_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_DEFAULT_RIPPLE
)
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
setting_tx, wallet, client)
# Submit the transaction and get results
reply = ""
try:
response = xrpl.transaction.send_reliable_submission(signed_tx,client)
reply = response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply = f"Submit failed: {e}"
return reply
response=xrpl.transaction.submit_and_wait(setting_tx,client,wallet)
return response.result

View File

@@ -1,5 +1,4 @@
import xrpl
import json
from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
from xrpl.models.requests import AccountNFTs
@@ -9,23 +8,20 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
def mint_token(seed, uri, flags, transfer_fee, taxon):
"""mint_token"""
# Get the client
mint_wallet=Wallet(seed, sequence=16237283)
minter_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
# Define the mint transaction
mint_tx=xrpl.models.transactions.NFTokenMint(
account=mint_wallet.classic_address,
account=minter_wallet.address,
uri=xrpl.utils.str_to_hex(uri),
flags=int(flags),
transfer_fee=int(transfer_fee),
nftoken_taxon=int(taxon)
)
# Sign and fill the transaction
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
mint_tx, mint_wallet, client)
# Submit the transaction and get results
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(mint_tx,client,minter_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"
@@ -45,19 +41,16 @@ def get_tokens(account):
def burn_token(seed, nftoken_id):
"""burn_token"""
# Get the client
owner_wallet=Wallet(seed, sequence=16237283)
owner_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
burn_tx=xrpl.models.transactions.NFTokenBurn(
account=owner_wallet.classic_address,
account=owner_wallet.address,
nftoken_id=nftoken_id
)
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
burn_tx, owner_wallet, client)
# Submit the transaction and get results
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(burn_tx,client,owner_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"

View File

@@ -12,7 +12,7 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
def create_sell_offer(seed, amount, nftoken_id, expiration, destination):
"""create_sell_offer"""
# Get the client
owner_wallet = Wallet(seed, sequence=16237283)
owner_wallet = Wallet.from_seed(seed)
client = JsonRpcClient(testnet_url)
expiration_date = datetime.now()
if expiration != '':
@@ -20,41 +20,34 @@ def create_sell_offer(seed, amount, nftoken_id, expiration, destination):
expiration_date = expiration_date + int(expiration)
# Define the sell offer
sell_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
account=owner_wallet.classic_address,
account=owner_wallet.address,
nftoken_id=nftoken_id,
amount=amount,
destination=destination if destination != '' else None,
expiration=expiration_date if expiration != '' else None,
flags=1
)
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
sell_offer_tx, owner_wallet, client)
# Submit the transaction and report the results
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(sell_offer_tx,client,owner_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"
return reply
def accept_sell_offer(seed, offer_index):
"""accept_sell_offer"""
buyer_wallet=Wallet(seed, sequence=16237283)
buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
account=buyer_wallet.classic_address,
nftoken_sell_offer=offer_index
)
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
accept_offer_tx, buyer_wallet, client)
# Submit the transaction and report the results
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(accept_offer_tx,client,buyer_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"
@@ -64,7 +57,7 @@ def accept_sell_offer(seed, offer_index):
def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
"""create_buy_offer"""
# Get the client
buyer_wallet=Wallet(seed, sequence=16237283)
buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
expiration_date=datetime.now()
if (expiration!=''):
@@ -72,7 +65,7 @@ def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
expiration_date=expiration_date + int(expiration)
# Define the buy offer transaction with an expiration date
buy_offer_tx=xrpl.models.transactions.NFTokenCreateOffer(
account=buyer_wallet.classic_address,
account=buyer_wallet.address,
nftoken_id=nft_id,
amount=amount,
owner=owner,
@@ -80,13 +73,10 @@ def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
destination=destination if destination!='' else None,
flags=0
)
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
buy_offer_tx, buyer_wallet, client)
# Submit the transaction and report the results
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(buy_offer_tx,client,buyer_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"
@@ -95,19 +85,16 @@ def create_buy_offer(seed, amount, nft_id, owner, expiration, destination):
def accept_buy_offer(seed, offer_index):
"""accept_buy_offer"""
buyer_wallet=Wallet(seed, sequence=16237283)
buyer_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
account=buyer_wallet.classic_address,
account=buyer_wallet.address,
nftoken_buy_offer=offer_index
)
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
accept_offer_tx, buyer_wallet, client)
# Submit the transaction and report the results
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(accept_offer_tx,client,buyer_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"
@@ -130,19 +117,17 @@ def get_offers(nft_id):
def cancel_offer(seed, nftoken_offer_ids):
"""cancel_offer"""
owner_wallet=Wallet(seed, sequence=16237283)
owner_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
tokenOfferIDs=[nftoken_offer_ids]
nftSellOffers="No sell offers"
cancel_offer_tx=xrpl.models.transactions.NFTokenCancelOffer(
account=owner_wallet.classic_address,
nftoken_offers=tokenOfferIDs
)
signed_tx = xrpl.transaction.safe_sign_and_autofill_transaction(
cancel_offer_tx, owner_wallet, client)
)
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(cancel_offer_tx,client,owner_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"

View File

@@ -1,5 +1,4 @@
import xrpl
import json
from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
testnet_url = "https://s.altnet.rippletest.net:51234"
@@ -7,7 +6,7 @@ testnet_url = "https://s.altnet.rippletest.net:51234"
def broker_sale(seed, sell_offer_index, buy_offer_index, broker_fee):
"""broker_sale"""
broker_wallet=Wallet(seed, sequence=16237283)
broker_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
accept_offer_tx=xrpl.models.transactions.NFTokenAcceptOffer(
account=broker_wallet.classic_address,
@@ -15,13 +14,10 @@ def broker_sale(seed, sell_offer_index, buy_offer_index, broker_fee):
nftoken_buy_offer=buy_offer_index,
nftoken_broker_fee=broker_fee
)
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
accept_offer_tx, broker_wallet, client)
# Submit the transaction and report the results
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(accept_offer_tx,client,broker_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply=f"Submit failed: {e}"

View File

@@ -1,47 +1,46 @@
import xrpl
import json
from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
testnet_url="https://s.altnet.rippletest.net:51234"
def set_minter(seed, minter):
"""set_minter"""
granter_wallet=Wallet(seed, sequence = 16237283)
granter_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
set_minter_tx=xrpl.models.transactions.AccountSet(
account=granter_wallet.classic_address,
account=granter_wallet.address,
nftoken_minter=minter,
set_flag=xrpl.models.transactions.AccountSetFlag.ASF_AUTHORIZED_NFTOKEN_MINTER
set_flag=xrpl.models.transactions.AccountSetAsfFlag.ASF_AUTHORIZED_NFTOKEN_MINTER
)
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
set_minter_tx, granter_wallet, client)
# Submit the transaction and report the results
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(set_minter_tx,client,
granter_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
response=f"Submit failed: {e}"
return response.result
reply=f"Submit failed: {e}"
return reply
def mint_other(seed, uri, flags, transfer_fee, taxon, issuer):
"""mint_other"""
minter_wallet=Wallet(seed, sequence=16237283)
minter_wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
mint_other_tx=xrpl.models.transactions.NFTokenMint(
account=minter_wallet.classic_address,
account=minter_wallet.address,
uri=xrpl.utils.str_to_hex(uri),
flags=int(flags),
transfer_fee=int(transfer_fee),
nftoken_taxon=int(taxon),
issuer=issuer
)
# Sign and fill the transaction
signed_tx=xrpl.transaction.safe_sign_and_autofill_transaction(
mint_other_tx, minter_wallet, client)
# Submit the transaction and report the results
reply=""
try:
response=xrpl.transaction.send_reliable_submission(signed_tx,client)
response=xrpl.transaction.submit_and_wait(mint_other_tx,client,
minter_wallet)
reply=response.result
except xrpl.transaction.XRPLReliableSubmissionException as e:
response=f"Submit failed: {e}"
return response.result
reply=f"Submit failed: {e}"
return reply

View File

@@ -0,0 +1,80 @@
import xrpl
from xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
from xrpl.models.requests import AccountNFTs
testnet_url = "https://s.altnet.rippletest.net:51234"
def batch_mint(seed, uri, flags, transfer_fee, taxon, count):
"""batch_mint"""
wallet=Wallet.from_seed(seed)
client=JsonRpcClient(testnet_url)
acct_info = xrpl.models.requests.account_info.AccountInfo(
account=wallet.classic_address,
ledger_index='validated'
)
get_seq_request = client.request(acct_info)
current_sequence=get_seq_request.result['account_data']['Sequence']
ticket_tx=xrpl.models.transactions.TicketCreate(
account=wallet.address,
ticket_count=int(count),
sequence=current_sequence
)
response=xrpl.transaction.submit_and_wait(ticket_tx,client,wallet)
ticket_numbers_req=xrpl.models.requests.AccountObjects(
account=wallet.address,
type='ticket'
)
ticket_response=client.request(ticket_numbers_req)
tickets=[int(0)] * int(count)
acct_objs= ticket_response.result['account_objects']
for x in range(int(count)):
tickets[x] = acct_objs[x]['TicketSequence']
reply=""
create_count=0
# Define the mint transaction
for x in range(int(count)):
mint_tx=xrpl.models.transactions.NFTokenMint(
account=wallet.classic_address,
uri=xrpl.utils.str_to_hex(uri),
flags=int(flags),
transfer_fee=int(transfer_fee),
ticket_sequence=tickets[x],
sequence=0,
nftoken_taxon=int(taxon)
)
# Submit the transaction and get results
try:
response=xrpl.transaction.submit_and_wait(mint_tx,client,
wallet)
create_count+=1
except xrpl.transaction.XRPLReliableSubmissionException as e:
reply+=f"Submit failed: {e}\n"
reply+=str(create_count)+' NFTs generated.'
return reply
def get_batch(seed, account):
"""get_batch"""
client=JsonRpcClient(testnet_url)
acct_nfts=AccountNFTs(
account=account,
limit=400
)
response=client.request(acct_nfts)
responses=response.result
while(acct_nfts.marker):
acct_nfts=AccountNFTs(
account=account,
limit=400,
marker=acct_nfts.marker
)
response=client.request(acct_nfts)
responses+=response.result
return responses