Skip to content

Commit

Permalink
try to use env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Mar 23, 2023
1 parent fe2ae8b commit ac8c9b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
7 changes: 3 additions & 4 deletions examples/atomic_transfers.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from typing import Dict, Any
from algosdk import transaction
from algosdk.v2client import algod
from utils import get_accounts
from utils import get_accounts, get_algod_client

algod_client = get_algod_client()

algod_address = "http://localhost:4001"
algod_token = "a" * 64
algod_client = algod.AlgodClient(algod_token, algod_address)

acct1, acct2, _ = get_accounts()
addr1, sk1 = acct1.address, acct1.private_key
Expand Down
3 changes: 2 additions & 1 deletion examples/overview.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Dict, Any
import json
from base64 import b64decode
from utils import get_accounts
from utils import get_accounts, get_algod_client

from algosdk import transaction
from algosdk.v2client import algod
Expand All @@ -21,6 +21,7 @@
)
# example: ALGOD_CREATE_CLIENT

algod_client = get_algod_client()
accts = get_accounts()

acct1 = accts.pop()
Expand Down
31 changes: 20 additions & 11 deletions examples/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import base64
from dataclasses import dataclass

Expand All @@ -8,26 +9,34 @@
from algosdk.kmd import KMDClient
from algosdk.wallet import Wallet

DEFAULT_KMD_ADDRESS = "http://localhost:4002"
DEFAULT_KMD_TOKEN = "a" * 64
KMD_ADDRESS = "http://localhost"
KMD_TOKEN = "a" * 64
KMD_PORT = os.getenv("KMD_PORT", default="4002")
KMD_URL = f"{KMD_ADDRESS}:{KMD_PORT}"

DEFAULT_KMD_WALLET_NAME = "unencrypted-default-wallet"
DEFAULT_KMD_WALLET_PASSWORD = ""

DEFAULT_ALGOD_ADDRESS = "http://localhost:4001"
DEFAULT_ALGOD_TOKEN = "a" * 64
ALGOD_ADDRESS = "http://localhost"
ALGOD_TOKEN = "a" * 64
ALGOD_PORT = os.getenv("ALGOD_PORT", default="4001")
ALGOD_URL = f"{ALGOD_ADDRESS}:{ALGOD_PORT}"


print(ALGOD_URL)
print(KMD_URL)

def get_algod_client(
addr: str = DEFAULT_ALGOD_ADDRESS, token: str = DEFAULT_ALGOD_TOKEN
addr: str = ALGOD_URL, token: str = ALGOD_TOKEN
) -> algod.AlgodClient:
return algod.AlgodClient(algod_token=token, algod_address=addr)


def get_kmd_client() -> KMDClient:
def get_kmd_client(
addr: str = KMD_URL, token: str = KMD_TOKEN
) -> KMDClient:
"""creates a new kmd client using the default sandbox parameters"""
return KMDClient(
kmd_token=DEFAULT_KMD_TOKEN, kmd_address=DEFAULT_KMD_ADDRESS
)
return KMDClient(kmd_token=token, kmd_address=addr)


def get_sandbox_default_wallet() -> Wallet:
Expand All @@ -52,8 +61,8 @@ class SandboxAccount:


def get_accounts(
kmd_address: str = DEFAULT_KMD_ADDRESS,
kmd_token: str = DEFAULT_KMD_TOKEN,
kmd_address: str = KMD_URL,
kmd_token: str = KMD_TOKEN,
wallet_name: str = DEFAULT_KMD_WALLET_NAME,
wallet_password: str = DEFAULT_KMD_WALLET_PASSWORD,
) -> list[SandboxAccount]:
Expand Down

0 comments on commit ac8c9b8

Please sign in to comment.