Skip to content

Commit

Permalink
Merge pull request #26 from nadineloepfe/solo-actions
Browse files Browse the repository at this point in the history
Solo actions
  • Loading branch information
nadineloepfe authored Dec 17, 2024
2 parents bd9b53e + 2d87524 commit e01c5b9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ OPERATOR_ID=<YOUR_OPERATOR_ID>
OPERATOR_KEY=<YOUR_PRIVATE_KEY>
RECIPIENT_ID=<RECIPIENT_ID>
RECIPIENT_KEY=<RECIPIENT_KEY>
ADMIN_KEY=<ADMIN_KEY>
TOKEN_ID=<TOKEN_ID>
TOKEN_NAME=<TOKEN_NAME>
TOKEN_SYMBOL=<TOKEN_SYMBOL>
TOKEN_SYMBOL=<TOKEN_SYMBOL>
NETWORK=<NETWORK>
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
run: |
echo "OPERATOR_ID=${{ steps.solo.outputs.accountId }}"
echo "OPERATOR_KEY=${{ steps.solo.outputs.privateKey }}"
echo "ADMIN_KEY=${{ steps.solo.outputs.privateKey }}"
echo "PUBLIC_KEY=${{ steps.solo.outputs.publicKey }}"
- name: Install your package
Expand All @@ -39,6 +40,8 @@ jobs:
env:
OPERATOR_ID: ${{ steps.solo.outputs.accountId }}
OPERATOR_KEY: ${{ steps.solo.outputs.privateKey }}
ADMIN_KEY: ${{ steps.solo.outputs.privateKey }}
PUBLIC_KEY: ${{ steps.solo.outputs.publicKey }}
NETWORK:
run: python test.py
NETWORK: solo
run: |
python test.py
13 changes: 10 additions & 3 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import os
import sys
from dotenv import load_dotenv
from src.client.network import Network
from src.client.client import Client
from src.account.account_id import AccountId
from src.account.account_create_transaction import AccountCreateTransaction
from src.crypto.private_key import PrivateKey
from src.tokens.token_create_transaction import TokenCreateTransaction
from src.tokens.token_associate_transaction import TokenAssociateTransaction
from src.tokens.token_id import TokenId
from src.transaction.transfer_transaction import TransferTransaction
from src.response_code import ResponseCode

load_dotenv()

def load_operator_credentials():
"""Load operator credentials from environment variables."""
Expand Down Expand Up @@ -54,6 +57,7 @@ def create_new_account(client, initial_balance=100000000):

def create_token(client, operator_id):
"""Create a new token and return its TokenId instance."""

transaction = (
TokenCreateTransaction()
.set_token_name("ExampleToken")
Expand All @@ -63,6 +67,7 @@ def create_token(client, operator_id):
.set_treasury_account_id(operator_id)
.freeze_with(client)
)

transaction.sign(client.operator_private_key)

try:
Expand All @@ -89,7 +94,7 @@ def associate_token(client, recipient_id, recipient_private_key, token_id):
.freeze_with(client)
)
transaction.sign(client.operator_private_key) # sign with operator's key (payer)
transaction.sign(recipient_private_key) # sign with newly created accounts key (recipient)
transaction.sign(recipient_private_key) # sign with newly created account's key (recipient)

try:
receipt = transaction.execute(client)
Expand Down Expand Up @@ -124,7 +129,9 @@ def transfer_token(client, recipient_id, token_id):
def main():
operator_id, operator_key = load_operator_credentials()

network = Network(node_address='localhost:50211', node_account_id=AccountId(0, 0, 3))
network_type = os.getenv('NETWORK')
network = Network(network=network_type)

client = Client(network)
client.set_operator(operator_id, operator_key)

Expand All @@ -134,4 +141,4 @@ def main():
transfer_token(client, recipient_id, token_id)

if __name__ == "__main__":
main()
main()

0 comments on commit e01c5b9

Please sign in to comment.