Skip to content

Commit ed1f6bd

Browse files
author
Conner Swann
committed
added wallet functionality
1 parent e7bfad2 commit ed1f6bd

1 file changed

Lines changed: 51 additions & 20 deletions

File tree

CodaClient.py

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _graphql_request(self, query: str, variables: dict = {}):
8383
else:
8484
print(response.text)
8585
raise Exception(
86-
"Query failed -- returned code {}. {}".format(response.status_code, query))
86+
"Query failed -- returned code {}. {} -> {}".format(response.status_code, query, response.json()))
8787

8888
async def _graphql_subscription(self, query: str, variables: dict = {}, callback = None):
8989
hello_message = {"type": "connection_init", "payload": {}}
@@ -225,6 +225,56 @@ def get_wallet(self, pk: str) -> dict:
225225
res = self._send_query(query, variables)
226226
return res["data"]
227227

228+
def create_wallet(self, password: str) -> dict:
229+
"""Creates a new Wallet.
230+
231+
Arguments:
232+
password {str} -- A password for the wallet to unlock.
233+
234+
Returns:
235+
dict -- Returns the "data" field of the JSON Response as a Dict.
236+
"""
237+
query = '''
238+
mutation ($password: String!) {
239+
createAccount(input: {password: $password}) {
240+
publicKey
241+
}
242+
}
243+
'''
244+
variables = {
245+
"password": password
246+
}
247+
res = self._send_query(query, variables)
248+
return res["data"]
249+
250+
def unlock_wallet(self, pk: str, password: str) -> dict:
251+
"""Unlocks the wallet for the specified Public Key.
252+
253+
Arguments:
254+
pk {str} -- A Public Key corresponding to a currently installed wallet.
255+
password {str} -- A password for the wallet to unlock.
256+
257+
Returns:
258+
dict -- Returns the "data" field of the JSON Response as a Dict.
259+
"""
260+
query = '''
261+
mutation ($publicKey: PublicKey!, $password: String!) {
262+
unlockWallet(input: {publicKey: $publicKey, password: $password}) {
263+
account {
264+
balance {
265+
total
266+
}
267+
}
268+
}
269+
}
270+
'''
271+
variables = {
272+
"publicKey": pk,
273+
"password": password
274+
}
275+
res = self._send_query(query, variables)
276+
return res["data"]
277+
228278
def get_blocks(self) -> dict:
229279
"""Gets the blocks known to the Coda Daemon.
230280
Mostly useful for Archive nodes.
@@ -336,25 +386,6 @@ def set_current_snark_worker(self, worker_pk: str, fee: str) -> dict:
336386
res = self._send_mutation(query, variables)
337387
return res["data"]
338388

339-
def create_wallet(self) -> dict:
340-
"""Creates a new wallet and returns the public key.
341-
342-
Arguments:
343-
N/A
344-
345-
Returns:
346-
dict -- Returns the "data" field of the JSON Response as a Dict
347-
"""
348-
query = '''
349-
mutation{
350-
addWallet {
351-
publicKey
352-
}
353-
}
354-
'''
355-
res = self._send_mutation(query)
356-
return res["data"]
357-
358389
def send_payment(self, to_pk: str, from_pk: str, amount: int, fee: int, memo: str) -> dict:
359390
"""Send a payment from the specified wallet to the specified target wallet.
360391

0 commit comments

Comments
 (0)