Skip to content

Commit

Permalink
Merge pull request #15 from crptomonkeys/aioeosabi
Browse files Browse the repository at this point in the history
Aioeosabi
  • Loading branch information
Vyryn committed Sep 8, 2024
2 parents 2b93853 + 164cc3d commit 18ed884
Show file tree
Hide file tree
Showing 8 changed files with 1,318 additions and 1,063 deletions.
21 changes: 16 additions & 5 deletions greenwiz/cogs/wax.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Optional, Union, Any

import discord
from aioeos import EosAccount
from aioeosabi import EosAccount
from discord import TextChannel, Forbidden, HTTPException
from discord.ext import commands, tasks # type: ignore

Expand Down Expand Up @@ -93,7 +93,9 @@ async def send_wax(self, ctx: commands.Context[Any], amount: int, destination: s
)
@commands.check(monkeyprinter())
@commands.check(scope())
async def send_nft(self, ctx: commands.Context[Any], destination: str, *, asset_id: int):
async def send_nft(
self, ctx: commands.Context[Any], destination: str, *, asset_id: int
):
asset_ids = [asset_id]
result = await self.bot.wax_con.transfer_assets(
destination, asset_ids, sender=ctx.author.name
Expand Down Expand Up @@ -204,7 +206,12 @@ async def cancel_old_links(
@commands.check(monkeyprinter())
@commands.check(scope())
async def claimlink(
self, ctx: commands.Context[Any], member: discord.Member, card: int = 0, *, memo=None
self,
ctx: commands.Context[Any],
member: discord.Member,
card: int = 0,
*,
memo=None,
):
if card != 0 and card < 1000:
# convert card # to template id
Expand Down Expand Up @@ -471,7 +478,9 @@ def in_check(message) -> bool:
)
if counter >= number and resp.author.id not in set(self.recent_drops):
break
assert resp is not None, "The winning message was deleted before a loot could be sent."
assert (
resp is not None
), "The winning message was deleted before a loot could be sent."
# Prevents the same person from receiving two drops in a row
self.recent_drops.appendleft(resp.author.id)
log("attempting to send a loot", "DBUG")
Expand Down Expand Up @@ -552,7 +561,9 @@ async def before_update_bot_known_assets(self):

@commands.command(description="Fetch the top monkeysmatch completers")
@commands.check(monkeyprinter())
async def monkeysmatch(self, ctx: commands.Context[Any], completions: Optional[int] = 1):
async def monkeysmatch(
self, ctx: commands.Context[Any], completions: Optional[int] = 1
):
"""Fetches all wax addresses who have completed at least n games of monkeysmatch. Default 1."""
res = await self.bot.wax_con.monkeysmatch_top(completions)

Expand Down
3 changes: 2 additions & 1 deletion greenwiz/utils/error_handler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""
The command error handler.
"""

import asyncio
import traceback
from json import JSONDecodeError

import discord
from aioeos.exceptions import EosAssertMessageException
from aioeosabi.exceptions import EosAssertMessageException
from discord.ext import commands

from utils.exceptions import (
Expand Down
3 changes: 2 additions & 1 deletion greenwiz/wax_chain/wax_contracts/atomicassets.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Helpers for creating actions on atomicassets contract. By Vyryn"""
from aioeos import types

from aioeosabi import types

contract = "atomicassets"

Expand Down
3 changes: 2 additions & 1 deletion greenwiz/wax_chain/wax_contracts/atomictoolsx.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Helpers for creating actions on atomictoolsx contract. By Vyryn"""
from aioeos import types

from aioeosabi import types

contract = "atomictoolsx"

Expand Down
3 changes: 2 additions & 1 deletion greenwiz/wax_chain/wax_contracts/monkeysmatch.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""Helpers for creating actions on monkeysmatch contract. By Vyryn"""

from os import urandom
from hashlib import sha256
from aioeos import types, EosKey
from aioeosabi import types, EosKey

contract = "monkeysmatch"

Expand Down
28 changes: 18 additions & 10 deletions greenwiz/wax_chain/wax_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@

import aiohttp
import discord
from aioeos import EosTransaction, EosKey, EosJsonRpc, EosAction, serializer, EosAccount
from aioeos.contracts import eosio_token
from aioeos.exceptions import EosAssertMessageException, EosRpcException
from aioeos.rpc import ERROR_NAME_MAP
from aioeosabi import (
EosTransaction,
EosKey,
EosJsonRpc,
EosAction,
serializer,
EosAccount,
)
from aioeosabi.contracts import eosio_token
from aioeosabi.exceptions import EosAssertMessageException, EosRpcException
from aioeosabi.rpc import ERROR_NAME_MAP
from aiohttp import ServerDisconnectedError, ClientConnectorError, ClientOSError
from discord import Forbidden, HTTPException

Expand Down Expand Up @@ -360,9 +367,7 @@ async def execute_transaction(
self.log(
f"Attempting to prepare action {action.account}::{action.name}::{action.data}"
)
abi_bin = await rpc.abi_json_to_bin(
action.account, action.name, action.data
)
abi_bin = await rpc.abi_json_to_bin(action)
action.data = binascii.unhexlify(abi_bin["binargs"])
suc = rpc.URL
self.log(
Expand Down Expand Up @@ -680,7 +685,8 @@ async def cancel_claimlinks(
_max: int = 50,
) -> tuple[bool, str]:
"""Cancels all the links with the specified IDs.
Raises an exception if there are more than _max links due to chain CPU constraints."""
Raises an exception if there are more than _max links due to chain CPU constraints.
"""
if len(link_ids) > _max:
raise AssertionError(
f"""{len(link_ids)} is too many claim links to cancel in one transaction,
Expand Down Expand Up @@ -1059,8 +1065,10 @@ async def send_link_start_to_finish(
raise AssertionError("Guild member' should always be a Member.")
while intro:
if not isinstance(introduced, discord.abc.Snowflake):
raise AssertionError("When post is classed as an intro and introduced role is defined,"
" introduced role should be addable.")
raise AssertionError(
"When post is classed as an intro and introduced role is defined,"
" introduced role should be addable."
)
# To ensure it gets added if discord messes up initially
await member.add_roles(introduced)
if introduced in member.roles:
Expand Down
Loading

0 comments on commit 18ed884

Please sign in to comment.