Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into staking-sdk
Browse files Browse the repository at this point in the history
# Conflicts:
#	fireblocks_sdk/sdk.py
  • Loading branch information
chenshooker committed Oct 29, 2023
2 parents 145b206 + 58f3f93 commit 7938fa8
Show file tree
Hide file tree
Showing 4 changed files with 1,219 additions and 314 deletions.
3 changes: 2 additions & 1 deletion fireblocks_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from fireblocks_sdk.sdk import FireblocksSDK
from fireblocks_sdk.ncw_sdk import FireblocksNCW
from fireblocks_sdk.sdk_token_provider import SdkTokenProvider
from fireblocks_sdk.api_types import *
from fireblocks_sdk.api_types import *
52 changes: 52 additions & 0 deletions fireblocks_sdk/api_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,40 @@ def __init__(self, total_amount_larger_than=None, asset_id=None, order_by=None,
self.after = after


class GetSmartTransferFilters(object):
""" Optional filters to apply for request
Args
query (string, optional): Search query string - either ticketId, asset or network name
statuses (DRAFT/PENDING_APPROVAL/OPEN/IN_SETTLEMENT/FULFILLED/EXPIRED/CANCELED, optional): array of ticket statuses
network_id (string, optional): networkId used in ticket
created_by_me (bool, optional): created by me flag
expires_after (string, optional): Lower bound of search range
expires_before (string, optional): Upper bound of search range
ticket_type (ASYNC/ATOMIC, optional): type of ticket
external_ref_id (string, optional): external ref id
after (string, optional): cursor string received from previous request
limit (number, optional): Results page size
Constraints
- You should only insert 'before' or 'after' (or none of them), but not both
"""

def __init__(self, query: Optional[str] = None, statuses: Optional[str] = None, network_id: Optional[str] = None,
created_by_me: Optional[bool] = None, expires_after: Optional[str] = None,
expires_before: Optional[str] = None, ticket_type: Optional[str] = None,
external_ref_id: Optional[str] = None, after: Optional[str] = None, limit: Optional[str] = None):
self.query = query
self.statuses = statuses
self.network_id = network_id
self.created_by_me = created_by_me
self.expires_after = expires_after
self.expires_before = expires_before
self.ticket_type = ticket_type
self.external_ref_id = external_ref_id
self.limit = limit
self.after = after


class GetOwnedNftsSortValues(str, Enum):
OWNERSHIP_LAST_UPDATE_TIME = "ownershipLastUpdateTime"
TOKEN_NAME = "name"
Expand All @@ -301,13 +335,31 @@ class NFTOwnershipStatusValues(str, Enum):
ARCHIVED = "ARCHIVED"


class NFTOwnershipStatusUpdatedPayload:
def __init__(self, asset_id: str, status: NFTOwnershipStatusValues):
self.asset_id = asset_id
self.status = status

def serialize(self) -> dict:
return {
'assetId': self.asset_id,
'status': self.status,
}


class GetOwnedCollectionsSortValue(str, Enum):
COLLECTION_NAME = "name"


class GetOwnedAssetsSortValues(str, Enum):
ASSET_NAME = "name"


class NFTsWalletTypeValues(str, Enum):
VAULT_ACCOUNT = "VAULT_ACCOUNT"
END_USER_WALLET = "END_USER_WALLET"


class OrderValues(str, Enum):
ASC = "ASC"
DESC = "DESC"
Expand Down
160 changes: 160 additions & 0 deletions fireblocks_sdk/ncw_sdk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
from .sdk import FireblocksSDK


class FireblocksNCW:
def __init__(self, sdk: FireblocksSDK):
self.sdk = sdk
self._wallet_url = "/v1/wallets"

def create_wallet(self):
url = "/v1/wallets"
return self.sdk._post_request(url)

def get_wallets(self):
return self.sdk._get_request(self._wallet_url)

def get_wallet(self, wallet_id: str):
url = f"{self._wallet_url}/{wallet_id}"
return self.sdk._get_request(url)

def enable_wallet(self, wallet_id: str, enabled: bool):
url = f"{self._wallet_url}/{wallet_id}/enable"
body = {"enabled": enabled}
return self.sdk._put_request(url, body)

def create_wallet_account(self, wallet_id: str):
url = f"{self._wallet_url}/{wallet_id}/accounts"
return self.sdk._post_request(url)

def get_wallet_accounts(
self,
wallet_id: str,
page_cursor: str = None,
page_size: int = None,
sort: str = None,
order: str = None,
enabled: bool = None,
):
url = f"{self._wallet_url}/{wallet_id}/accounts"
query_params = {}

if page_cursor:
query_params["pageCursor"] = page_cursor

if page_size:
query_params["pageSize"] = page_size

if sort:
query_params["sort"] = sort

if order:
query_params["order"] = order

if enabled:
query_params["enabled"] = enabled

return self.sdk._get_request(url, query_params=query_params)

def get_wallet_account(self, wallet_id: str, account_id: str):
url = f"{self._wallet_url}/{wallet_id}/accounts/{account_id}"
return self.sdk._get_request(url)

def get_wallet_assets(
self,
wallet_id: str,
account_id: str,
page_cursor: str = None,
page_size: int = None,
sort: str = None,
order: str = None,
enabled: bool = None,
):
url = f"{self._wallet_url}/{wallet_id}/accounts/{account_id}/assets"
query_params = {}

if page_cursor:
query_params["pageCursor"] = page_cursor

if page_size:
query_params["pageSize"] = page_size

if sort:
query_params["sort"] = sort

if order:
query_params["order"] = order

if enabled:
query_params["enabled"] = enabled

return self.sdk._get_request(url, query_params=query_params)

def get_wallet_asset(self, wallet_id: str, account_id: str, asset_id: str):
url = f"{self._wallet_url}/{wallet_id}/accounts/{account_id}/assets/{asset_id}"
return self.sdk._get_request(url)

def activate_wallet_asset(self, wallet_id: str, account_id: str, asset_id: str):
url = f"{self._wallet_url}/{wallet_id}/accounts/{account_id}/assets/{asset_id}"
return self.sdk._post_request(url)

def refresh_wallet_asset_balance(
self, wallet_id: str, account_id: str, asset_id: str
):
url = f"{self._wallet_url}/{wallet_id}/accounts/{account_id}/assets/{asset_id}/balance"
return self.sdk._put_request(url)

def get_wallet_asset_balance(
self, wallet_id: str, account_id: str, asset_id: str
):
url = f"{self._wallet_url}/{wallet_id}/accounts/{account_id}/assets/{asset_id}/balance"
return self.sdk._get_request(url)

def get_wallet_asset_addresses(
self,
wallet_id: str,
account_id: str,
asset_id: str,
page_cursor: str = None,
page_size: int = None,
sort: str = None,
order: str = None,
enabled: bool = None,
):
url = f"{self._wallet_url}/{wallet_id}/accounts/{account_id}/assets/{asset_id}/addresses"
query_params = {}

if page_cursor:
query_params["pageCursor"] = page_cursor

if page_size:
query_params["pageSize"] = page_size

if sort:
query_params["sort"] = sort

if order:
query_params["order"] = order

if enabled:
query_params["enabled"] = enabled

return self.sdk._get_request(url, query_params=query_params)

def get_devices(self, wallet_id: str):
url = f"{self._wallet_url}/{wallet_id}/devices"
return self.sdk._get_request(url)

def enable_device(self, wallet_id: str, device_id: str, enabled: bool):
url = f"{self._wallet_url}/{wallet_id}/devices/{device_id}"
body = {"enabled": enabled}

return self.sdk._put_request(url, body)

def invoke_wallet_rpc(self, wallet_id: str, device_id: str, payload: str):
"""
payload: stringified JSON, message originated in the NCW SDK
"""
url = f"{self._wallet_url}/{wallet_id}/devices/{device_id}/rpc"
body = {"payload": payload}

return self.sdk._post_request(url, body)
Loading

0 comments on commit 7938fa8

Please sign in to comment.