This commit is contained in:
William Luke 2021-10-29 11:34:37 +03:00
parent f856ca3f68
commit 0c84e970ad

View File

@ -18,23 +18,14 @@ args = argparser.parse_args()
config = cic_eth.cli.Config.from_args(args, arg_flags, local_arg_flags)
celery_app = cic_eth.cli.CeleryApp.from_config(config)
chain_spec = config.get('CHAIN_SPEC')
redis_host = config.get('REDIS_HOST')
redis_port = config.get('REDIS_PORT')
redis_db = config.get('REDIS_DB')
celery_queue = config.get('CELERY_QUEUE')
def call(method, *args):
chain_spec = config.get('CHAIN_SPEC')
redis_host = config.get('REDIS_HOST')
redis_port = config.get('REDIS_PORT')
redis_db = config.get('REDIS_DB')
celery_queue = config.get('CELERY_QUEUE')
redis_channel = str(uuid.uuid4())
r = redis.Redis(redis_host, redis_port, redis_db)
ps = r.pubsub()
ps.subscribe(redis_channel)
ps.get_message() # Subscription Object
def init_api(redis_channel: str):
api = Api(
chain_spec,
queue=celery_queue,
@ -43,6 +34,17 @@ def call(method, *args):
callback_task='cic_eth.callbacks.redis.redis',
callback_queue=celery_queue,
)
return api
def call(method, *args):
redis_channel = str(uuid.uuid4())
r = redis.Redis(redis_host, redis_port, redis_db)
ps = r.pubsub()
ps.subscribe(redis_channel)
ps.get_message() # Subscription Object
api = init_api(redis_channel)
print(args)
getattr(api, method)(*args)
@ -69,14 +71,14 @@ class Token(ObjectType):
class TokenBalance(ObjectType):
address = String()
converters = List(String)
balance_network = Int()
balance_incoming = Int(default_value=0)
balance_outgoing = Int(default_value=0)
balance_available = Int(default_value=0)
balance_network = String(default_value="0")
balance_incoming = String(default_value="0")
balance_outgoing = String(default_value="0")
balance_available = String(default_value="0")
def resolve_balance_available(parent, info):
print(parent)
return (parent.balance_network + parent.balance_incoming) - parent.balance_outgoing
return str(int(parent.balance_network) + int(parent.balance_incoming) - int(parent.balance_outgoing))
class Query(ObjectType):
@ -95,7 +97,23 @@ class Query(ObjectType):
data = call('balance', address, token_symbols, include_pending)
print(data)
#[{'address': '3ff776b6f888980def9d4220858803f9dc5e341e', 'converters': [], 'balance_network': 0}]
return map(lambda token: TokenBalance(**token), data)
return map(lambda token: TokenBalance(
address=token.get("address"),
converters=token.get("converters"),
balance_network=str(token.get("balance_network") or "0"),
balance_incoming=str(token.get("balance_incoming") or "0"),
balance_outgoing=str(token.get("balance_outgoing") or "0"),
balance_available=str(token.get("balance_available" or "0"))
), data)
transactions = Field(String, address=String(
required=True), limit=Int(default_value=10))
def resolve_transactions(root, info, address, limit):
data = call('list', address, limit)
print(data)
#[{'address': '3ff776b6f888980def9d4220858803f9dc5e341e', 'converters': [], 'balance_network': 0}]
return "test"
class CreateAccount(Mutation):
@ -127,12 +145,15 @@ class Transfer(Mutation):
token_symbol):
print(from_address, to_address, value, token_symbol)
data = call('transfer', from_address,
to_address,
value,
token_symbol)
print(data)
return data
redis_channel = str(uuid.uuid4())
api = init_api(redis_channel)
t = api.transfer(from_address, to_address,
int(value * (10**6)), token_symbol)
print(f"t {t}")
print(f"transfer {t.get_leaf()}")
print(f"transfer {t.successful()}")
return t.get()
# 0x0000000000000000000000000000000000000000
@ -174,8 +195,8 @@ query_with_argument = """
}
"""
result = schema.execute(query_with_argument)
print(result)
# result = schema.execute(query_with_argument)
# print(result)
mutation_with_argument = """
@ -186,8 +207,8 @@ mutation {
}
"""
m_result = schema.execute(mutation_with_argument)
print(m_result)
# m_result = schema.execute(mutation_with_argument)
# print(m_result)
balance_query = """
@ -201,17 +222,17 @@ query {
}
"""
balance_query_result = schema.execute(balance_query)
print(balance_query_result)
# balance_query_result = schema.execute(balance_query)
# print(balance_query_result)
transfer_mutation = """
mutation {
transfer(fromAddress :"0x0000000000000000000000000000000000000000",
transfer(fromAddress :"0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C",
toAddress: "0x82e66cf2766bf20672a605bbf5a6faaa12d5b907"
value: 5000
value: 20
tokenSymbol: "GFT" ){
test
}
}
@ -222,7 +243,7 @@ print(transfer_mutation_result)
balance_query = """
query {
balance(address:"0x82e66cf2766bf20672a605bbf5a6faaa12d5b907", tokenSymbols:["GFT"]){
balance(address:"0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C", tokenSymbols:["GFT"]){
balanceNetwork
balanceIncoming
balanceOutgoing
@ -231,5 +252,15 @@ query {
}
"""
balance_query_result = schema.execute(balance_query)
print(balance_query_result)
# balance_query_result = schema.execute(balance_query)
# print(balance_query_result)
transactions_query = """
query {
transactions(address:"0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C")
}
"""
# transactions_query_result = schema.execute(transactions_query)
# print(transactions_query_result)