-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathblockchain.py
More file actions
196 lines (142 loc) · 7.37 KB
/
blockchain.py
File metadata and controls
196 lines (142 loc) · 7.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
from typing import List, Optional
from typing_extensions import TypedDict
from ..._internal.api_client import InternalApiClient, InternalApiClientSync
from ...types import BlindpayApiResponse, Network
class GetBlockchainWalletMessageResponse(TypedDict):
message: str
class BlockchainWallet(TypedDict):
id: str
name: str
network: Network
address: Optional[str]
signature_tx_hash: Optional[str]
is_account_abstraction: bool
receiver_id: str
ListBlockchainWalletsResponse = List[BlockchainWallet]
GetBlockchainWalletResponse = BlockchainWallet
CreateBlockchainWalletResponse = BlockchainWallet
class CreateBlockchainWalletWithAddressInput(TypedDict):
receiver_id: str
name: str
network: Network
address: str
class CreateBlockchainWalletWithHashInput(TypedDict):
receiver_id: str
name: str
network: Network
signature_tx_hash: str
class GetBlockchainWalletInput(TypedDict):
receiver_id: str
id: str
class DeleteBlockchainWalletInput(TypedDict):
receiver_id: str
id: str
class CreateAssetTrustlineResponse(TypedDict):
xdr: str
class MintUsdbStellarInput(TypedDict):
address: str
amount: str
signedXdr: str
class MintUsdbSolanaInput(TypedDict):
address: str
amount: str
class MintUsdbSolanaResponse(TypedDict):
success: bool
signature: str
class PrepareSolanaDelegationTransactionInput(TypedDict):
amount: str
owner_address: str
token_address: str
class PrepareSolanaDelegationTransactionResponse(TypedDict):
success: bool
transaction: str
class BlockchainWalletsResource:
def __init__(self, instance_id: str, client: InternalApiClient):
self._instance_id = instance_id
self._client = client
async def list(self, receiver_id: str) -> BlindpayApiResponse[ListBlockchainWalletsResponse]:
return await self._client.get(f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets")
async def create_with_address(
self, data: CreateBlockchainWalletWithAddressInput
) -> BlindpayApiResponse[CreateBlockchainWalletResponse]:
receiver_id = data["receiver_id"]
payload = {k: v for k, v in data.items() if k != "receiver_id"}
payload["is_account_abstraction"] = True
return await self._client.post(
f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets", payload
)
async def create_with_hash(
self, data: CreateBlockchainWalletWithHashInput
) -> BlindpayApiResponse[CreateBlockchainWalletResponse]:
receiver_id = data["receiver_id"]
payload = {k: v for k, v in data.items() if k != "receiver_id"}
payload["is_account_abstraction"] = False
return await self._client.post(
f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets", payload
)
async def get_wallet_message(self, receiver_id: str) -> BlindpayApiResponse[GetBlockchainWalletMessageResponse]:
return await self._client.get(
f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets/sign-message"
)
async def get(self, data: GetBlockchainWalletInput) -> BlindpayApiResponse[GetBlockchainWalletResponse]:
receiver_id = data["receiver_id"]
id = data["id"]
return await self._client.get(f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets/{id}")
async def delete(self, data: DeleteBlockchainWalletInput) -> BlindpayApiResponse[None]:
receiver_id = data["receiver_id"]
id = data["id"]
return await self._client.delete(
f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets/{id}"
)
async def create_asset_trustline(self, address: str) -> BlindpayApiResponse[CreateAssetTrustlineResponse]:
return await self._client.post(f"/instances/{self._instance_id}/create-asset-trustline", {"address": address})
async def mint_usdb_stellar(self, data: MintUsdbStellarInput) -> BlindpayApiResponse[None]:
return await self._client.post(f"/instances/{self._instance_id}/mint-usdb-stellar", data)
async def mint_usdb_solana(self, data: MintUsdbSolanaInput) -> BlindpayApiResponse[MintUsdbSolanaResponse]:
return await self._client.post(f"/instances/{self._instance_id}/mint-usdb-solana", data)
async def prepare_solana_delegation_transaction(
self, data: PrepareSolanaDelegationTransactionInput
) -> BlindpayApiResponse[PrepareSolanaDelegationTransactionResponse]:
return await self._client.post(f"/instances/{self._instance_id}/prepare-delegate-solana", data)
class BlockchainWalletsResourceSync:
def __init__(self, instance_id: str, client: InternalApiClientSync):
self._instance_id = instance_id
self._client = client
def list(self, receiver_id: str) -> BlindpayApiResponse[ListBlockchainWalletsResponse]:
return self._client.get(f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets")
def create_with_address(
self, data: CreateBlockchainWalletWithAddressInput
) -> BlindpayApiResponse[CreateBlockchainWalletResponse]:
receiver_id = data["receiver_id"]
payload = {k: v for k, v in data.items() if k != "receiver_id"}
payload["is_account_abstraction"] = True
return self._client.post(f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets", payload)
def create_with_hash(
self, data: CreateBlockchainWalletWithHashInput
) -> BlindpayApiResponse[CreateBlockchainWalletResponse]:
receiver_id = data["receiver_id"]
payload = {k: v for k, v in data.items() if k != "receiver_id"}
payload["is_account_abstraction"] = False
return self._client.post(f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets", payload)
def get_wallet_message(self, receiver_id: str) -> BlindpayApiResponse[GetBlockchainWalletMessageResponse]:
return self._client.get(
f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets/sign-message"
)
def get(self, data: GetBlockchainWalletInput) -> BlindpayApiResponse[GetBlockchainWalletResponse]:
receiver_id = data["receiver_id"]
id = data["id"]
return self._client.get(f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets/{id}")
def delete(self, data: DeleteBlockchainWalletInput) -> BlindpayApiResponse[None]:
receiver_id = data["receiver_id"]
id = data["id"]
return self._client.delete(f"/instances/{self._instance_id}/receivers/{receiver_id}/blockchain-wallets/{id}")
def create_asset_trustline(self, address: str) -> BlindpayApiResponse[CreateAssetTrustlineResponse]:
return self._client.post(f"/instances/{self._instance_id}/create-asset-trustline", {"address": address})
def mint_usdb_stellar(self, data: MintUsdbStellarInput) -> BlindpayApiResponse[None]:
return self._client.post(f"/instances/{self._instance_id}/mint-usdb-stellar", data)
def create_blockchain_wallets_resource(instance_id: str, client: InternalApiClient) -> BlockchainWalletsResource:
return BlockchainWalletsResource(instance_id, client)
def create_blockchain_wallets_resource_sync(
instance_id: str, client: InternalApiClientSync
) -> BlockchainWalletsResourceSync:
return BlockchainWalletsResourceSync(instance_id, client)