misc
This commit is contained in:
parent
f856ca3f68
commit
0c84e970ad
@ -18,23 +18,14 @@ args = argparser.parse_args()
|
|||||||
config = cic_eth.cli.Config.from_args(args, arg_flags, local_arg_flags)
|
config = cic_eth.cli.Config.from_args(args, arg_flags, local_arg_flags)
|
||||||
|
|
||||||
celery_app = cic_eth.cli.CeleryApp.from_config(config)
|
celery_app = cic_eth.cli.CeleryApp.from_config(config)
|
||||||
|
|
||||||
|
|
||||||
def call(method, *args):
|
|
||||||
chain_spec = config.get('CHAIN_SPEC')
|
chain_spec = config.get('CHAIN_SPEC')
|
||||||
redis_host = config.get('REDIS_HOST')
|
redis_host = config.get('REDIS_HOST')
|
||||||
redis_port = config.get('REDIS_PORT')
|
redis_port = config.get('REDIS_PORT')
|
||||||
redis_db = config.get('REDIS_DB')
|
redis_db = config.get('REDIS_DB')
|
||||||
celery_queue = config.get('CELERY_QUEUE')
|
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(
|
api = Api(
|
||||||
chain_spec,
|
chain_spec,
|
||||||
queue=celery_queue,
|
queue=celery_queue,
|
||||||
@ -43,6 +34,17 @@ def call(method, *args):
|
|||||||
callback_task='cic_eth.callbacks.redis.redis',
|
callback_task='cic_eth.callbacks.redis.redis',
|
||||||
callback_queue=celery_queue,
|
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)
|
print(args)
|
||||||
|
|
||||||
getattr(api, method)(*args)
|
getattr(api, method)(*args)
|
||||||
@ -69,14 +71,14 @@ class Token(ObjectType):
|
|||||||
class TokenBalance(ObjectType):
|
class TokenBalance(ObjectType):
|
||||||
address = String()
|
address = String()
|
||||||
converters = List(String)
|
converters = List(String)
|
||||||
balance_network = Int()
|
balance_network = String(default_value="0")
|
||||||
balance_incoming = Int(default_value=0)
|
balance_incoming = String(default_value="0")
|
||||||
balance_outgoing = Int(default_value=0)
|
balance_outgoing = String(default_value="0")
|
||||||
balance_available = Int(default_value=0)
|
balance_available = String(default_value="0")
|
||||||
|
|
||||||
def resolve_balance_available(parent, info):
|
def resolve_balance_available(parent, info):
|
||||||
print(parent)
|
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):
|
class Query(ObjectType):
|
||||||
@ -95,7 +97,23 @@ class Query(ObjectType):
|
|||||||
data = call('balance', address, token_symbols, include_pending)
|
data = call('balance', address, token_symbols, include_pending)
|
||||||
print(data)
|
print(data)
|
||||||
#[{'address': '3ff776b6f888980def9d4220858803f9dc5e341e', 'converters': [], 'balance_network': 0}]
|
#[{'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):
|
class CreateAccount(Mutation):
|
||||||
@ -127,12 +145,15 @@ class Transfer(Mutation):
|
|||||||
token_symbol):
|
token_symbol):
|
||||||
print(from_address, to_address, value, token_symbol)
|
print(from_address, to_address, value, token_symbol)
|
||||||
|
|
||||||
data = call('transfer', from_address,
|
redis_channel = str(uuid.uuid4())
|
||||||
to_address,
|
|
||||||
value,
|
api = init_api(redis_channel)
|
||||||
token_symbol)
|
t = api.transfer(from_address, to_address,
|
||||||
print(data)
|
int(value * (10**6)), token_symbol)
|
||||||
return data
|
print(f"t {t}")
|
||||||
|
print(f"transfer {t.get_leaf()}")
|
||||||
|
print(f"transfer {t.successful()}")
|
||||||
|
return t.get()
|
||||||
# 0x0000000000000000000000000000000000000000
|
# 0x0000000000000000000000000000000000000000
|
||||||
|
|
||||||
|
|
||||||
@ -174,8 +195,8 @@ query_with_argument = """
|
|||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
result = schema.execute(query_with_argument)
|
# result = schema.execute(query_with_argument)
|
||||||
print(result)
|
# print(result)
|
||||||
|
|
||||||
|
|
||||||
mutation_with_argument = """
|
mutation_with_argument = """
|
||||||
@ -186,8 +207,8 @@ mutation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
m_result = schema.execute(mutation_with_argument)
|
# m_result = schema.execute(mutation_with_argument)
|
||||||
print(m_result)
|
# print(m_result)
|
||||||
|
|
||||||
|
|
||||||
balance_query = """
|
balance_query = """
|
||||||
@ -201,17 +222,17 @@ query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
balance_query_result = schema.execute(balance_query)
|
# balance_query_result = schema.execute(balance_query)
|
||||||
print(balance_query_result)
|
# print(balance_query_result)
|
||||||
|
|
||||||
|
|
||||||
transfer_mutation = """
|
transfer_mutation = """
|
||||||
mutation {
|
mutation {
|
||||||
transfer(fromAddress :"0x0000000000000000000000000000000000000000",
|
transfer(fromAddress :"0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C",
|
||||||
toAddress: "0x82e66cf2766bf20672a605bbf5a6faaa12d5b907"
|
toAddress: "0x82e66cf2766bf20672a605bbf5a6faaa12d5b907"
|
||||||
value: 5000
|
value: 20
|
||||||
tokenSymbol: "GFT" ){
|
tokenSymbol: "GFT" ){
|
||||||
test
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +243,7 @@ print(transfer_mutation_result)
|
|||||||
|
|
||||||
balance_query = """
|
balance_query = """
|
||||||
query {
|
query {
|
||||||
balance(address:"0x82e66cf2766bf20672a605bbf5a6faaa12d5b907", tokenSymbols:["GFT"]){
|
balance(address:"0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C", tokenSymbols:["GFT"]){
|
||||||
balanceNetwork
|
balanceNetwork
|
||||||
balanceIncoming
|
balanceIncoming
|
||||||
balanceOutgoing
|
balanceOutgoing
|
||||||
@ -231,5 +252,15 @@ query {
|
|||||||
}
|
}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
balance_query_result = schema.execute(balance_query)
|
# balance_query_result = schema.execute(balance_query)
|
||||||
print(balance_query_result)
|
# print(balance_query_result)
|
||||||
|
|
||||||
|
|
||||||
|
transactions_query = """
|
||||||
|
query {
|
||||||
|
transactions(address:"0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C")
|
||||||
|
}
|
||||||
|
|
||||||
|
"""
|
||||||
|
# transactions_query_result = schema.execute(transactions_query)
|
||||||
|
# print(transactions_query_result)
|
||||||
|
Loading…
Reference in New Issue
Block a user