Skip to content

Commit

Permalink
style: reformat examples/
Browse files Browse the repository at this point in the history
  • Loading branch information
gtors committed Apr 18, 2024
1 parent 92dd303 commit 05b935a
Show file tree
Hide file tree
Showing 13 changed files with 583 additions and 181 deletions.
15 changes: 4 additions & 11 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11"]
python-version: ["3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand All @@ -27,14 +27,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
python -m pip install ruff
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
ruff check .
104 changes: 72 additions & 32 deletions examples/tokens/jetton/mint.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,124 @@
from tonsdk_ng.contract.token.ft import JettonMinter, JettonWallet
from tonsdk_ng.contract import Address
from tonsdk_ng.utils import to_nano, bytes_to_b64str
from tonsdk_ng.contract.token.ft import JettonMinter, JettonWallet
from tonsdk_ng.contract.wallet import Wallets, WalletVersionEnum
from tonsdk_ng.utils import bytes_to_b64str, to_nano


def create_jetton_minter():
minter = JettonMinter(admin_address=Address('admin address'),
jetton_content_uri='https://raw.githubusercontent.com/yungwine/pyton-lessons/master/lesson-6/token_data.json',
jetton_wallet_code_hex=JettonWallet.code)
minter = JettonMinter(
admin_address=Address("admin address"),
jetton_content_uri="https://raw.githubusercontent.com/yungwine/pyton-lessons/master/lesson-6/token_data.json",
jetton_wallet_code_hex=JettonWallet.code,
)

return minter


def create_mint_body():
minter = create_jetton_minter()

body = minter.create_mint_body(destination=Address('address'),
jetton_amount=to_nano(int('mint amount'), 'ton'))
body = minter.create_mint_body(
destination=Address("address"),
jetton_amount=to_nano(int("mint amount"), "ton"),
)
return body


def create_change_owner_body():
minter = create_jetton_minter()

body = minter.create_change_admin_body(
new_admin_address=Address('EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c'))
new_admin_address=Address(
"EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c"
)
)
return body


def create_burn_body():
body = JettonWallet().create_burn_body(
jetton_amount=to_nano(int('burn amount'), 'ton'))
jetton_amount=to_nano(int("burn amount"), "ton")
)
return body


"""your wallet mnemonics"""
mnemonics = ['always', 'crystal', 'grab', 'glance', 'cause', 'dismiss', 'answer', 'expose', 'once', 'session',
'tunnel', 'topic', 'defense', 'such', 'army', 'smile', 'exhibit', 'misery', 'runway', 'tone', 'want',
'primary', 'piano', 'language']

mnemonics, pub_k, priv_k, wallet = Wallets.from_mnemonics(mnemonics=mnemonics, version=WalletVersionEnum.v3r2,
workchain=0)
mnemonics = [
"always",
"crystal",
"grab",
"glance",
"cause",
"dismiss",
"answer",
"expose",
"once",
"session",
"tunnel",
"topic",
"defense",
"such",
"army",
"smile",
"exhibit",
"misery",
"runway",
"tone",
"want",
"primary",
"piano",
"language",
]

mnemonics, pub_k, priv_k, wallet = Wallets.from_mnemonics(
mnemonics=mnemonics, version=WalletVersionEnum.v3r2, workchain=0
)

"""deploy jetton minter"""
minter = create_jetton_minter()
collection_state_init = minter.create_state_init()['state_init']
collection_state_init = minter.create_state_init()["state_init"]

query = wallet.create_transfer_message(to_addr=minter.address.to_string(),
amount=to_nano(0.02, 'ton'),
state_init=collection_state_init,
seqno=int('wallet seqno'))
query = wallet.create_transfer_message(
to_addr=minter.address.to_string(),
amount=to_nano(0.02, "ton"),
state_init=collection_state_init,
seqno=int("wallet seqno"),
)


"""mint tokens"""
body = create_mint_body()
minter = create_jetton_minter()

query = wallet.create_transfer_message(to_addr=minter.address.to_string(),
amount=to_nano(0.04, 'ton'),
seqno=int('wallet seqno'),
payload=body)
query = wallet.create_transfer_message(
to_addr=minter.address.to_string(),
amount=to_nano(0.04, "ton"),
seqno=int("wallet seqno"),
payload=body,
)


"""change owner address"""
body = create_change_owner_body()
minter = create_jetton_minter()

query = wallet.create_transfer_message(to_addr=minter.address.to_string(),
amount=to_nano(0.04, 'ton'),
seqno=int('wallet seqno'),
payload=body)
query = wallet.create_transfer_message(
to_addr=minter.address.to_string(),
amount=to_nano(0.04, "ton"),
seqno=int("wallet seqno"),
payload=body,
)


"""burn tokens"""
body = create_burn_body()

query = wallet.create_transfer_message(to_addr='address of your jetton wallet',
amount=to_nano(0.04, 'ton'),
seqno=int('wallet seqno'),
payload=body)
query = wallet.create_transfer_message(
to_addr="address of your jetton wallet",
amount=to_nano(0.04, "ton"),
seqno=int("wallet seqno"),
payload=body,
)


"""then send boc to blockchain"""
Expand Down
53 changes: 39 additions & 14 deletions examples/tokens/jetton/transfer.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,51 @@
from tonsdk_ng.contract.token.ft import JettonWallet
from tonsdk_ng.utils import to_nano, bytes_to_b64str, Address
from tonsdk_ng.contract.wallet import Wallets, WalletVersionEnum

from tonsdk_ng.utils import Address, bytes_to_b64str, to_nano

"""your wallet mnemonics"""
mnemonics = ['always', 'crystal', 'grab', 'glance', 'cause', 'dismiss', 'answer', 'expose', 'once', 'session',
'tunnel', 'topic', 'defense', 'such', 'army', 'smile', 'exhibit', 'misery', 'runway', 'tone', 'want',
'primary', 'piano', 'language']
mnemonics, pub_k, priv_k, wallet = Wallets.from_mnemonics(mnemonics=mnemonics, version=WalletVersionEnum.v3r2,
workchain=0)
mnemonics = [
"always",
"crystal",
"grab",
"glance",
"cause",
"dismiss",
"answer",
"expose",
"once",
"session",
"tunnel",
"topic",
"defense",
"such",
"army",
"smile",
"exhibit",
"misery",
"runway",
"tone",
"want",
"primary",
"piano",
"language",
]
mnemonics, pub_k, priv_k, wallet = Wallets.from_mnemonics(
mnemonics=mnemonics, version=WalletVersionEnum.v3r2, workchain=0
)


"""transfer"""
body = JettonWallet().create_transfer_body(
to_address=Address('address'),
jetton_amount=to_nano(float('jettons amount'), 'ton'),
)
to_address=Address("address"),
jetton_amount=to_nano(float("jettons amount"), "ton"),
)

query = wallet.create_transfer_message(to_addr='your jetton wallet address',
amount=to_nano(0.1, 'ton'),
seqno=int('wallet seqno'),
payload=body)
query = wallet.create_transfer_message(
to_addr="your jetton wallet address",
amount=to_nano(0.1, "ton"),
seqno=int("wallet seqno"),
payload=body,
)

"""then send boc to blockchain"""
boc = bytes_to_b64str(query["message"].to_boc(False))
Loading

0 comments on commit 05b935a

Please sign in to comment.