mirror of
https://github.com/basicswap/basicswap.git
synced 2025-01-18 16:44:34 +00:00
api: Start automationstrategies
This commit is contained in:
parent
6ccfd93997
commit
577849f01c
3 changed files with 64 additions and 13 deletions
|
@ -1259,7 +1259,7 @@ class BasicSwap(BaseApp):
|
|||
finally:
|
||||
self.closeSession(session)
|
||||
|
||||
def listIdentities(self, filters):
|
||||
def listIdentities(self, filters={}):
|
||||
try:
|
||||
session = self.openSession()
|
||||
|
||||
|
@ -1303,7 +1303,7 @@ class BasicSwap(BaseApp):
|
|||
rv.append(identity)
|
||||
return rv
|
||||
finally:
|
||||
self.closeSession(session)
|
||||
self.closeSession(session, commit=False)
|
||||
|
||||
def vacuumDB(self):
|
||||
try:
|
||||
|
@ -6109,10 +6109,9 @@ class BasicSwap(BaseApp):
|
|||
self.mxDB.release()
|
||||
|
||||
def listAutomationStrategies(self, filters={}):
|
||||
self.mxDB.acquire()
|
||||
try:
|
||||
session = self.openSession()
|
||||
rv = []
|
||||
session = scoped_session(self.session_factory)
|
||||
|
||||
query_str = 'SELECT strats.record_id, strats.label, strats.type_ind FROM automationstrategies AS strats'
|
||||
query_str += ' WHERE strats.active_ind = 1 '
|
||||
|
@ -6137,9 +6136,7 @@ class BasicSwap(BaseApp):
|
|||
rv.append(row)
|
||||
return rv
|
||||
finally:
|
||||
session.close()
|
||||
session.remove()
|
||||
self.mxDB.release()
|
||||
self.closeSession(session, commit=False)
|
||||
|
||||
def getAutomationStrategy(self, strategy_id: int):
|
||||
try:
|
||||
|
@ -6158,19 +6155,16 @@ class BasicSwap(BaseApp):
|
|||
finally:
|
||||
self.closeSession(session)
|
||||
|
||||
def getLinkedStrategy(self, linked_type, linked_id):
|
||||
self.mxDB.acquire()
|
||||
def getLinkedStrategy(self, linked_type: int, linked_id):
|
||||
try:
|
||||
session = scoped_session(self.session_factory)
|
||||
session = self.openSession()
|
||||
query_str = 'SELECT links.strategy_id, strats.label FROM automationlinks links' + \
|
||||
' LEFT JOIN automationstrategies strats ON strats.record_id = links.strategy_id' + \
|
||||
' WHERE links.linked_type = {} AND links.linked_id = x\'{}\' AND links.active_ind = 1'.format(int(linked_type), linked_id.hex())
|
||||
q = session.execute(query_str).first()
|
||||
return q
|
||||
finally:
|
||||
session.close()
|
||||
session.remove()
|
||||
self.mxDB.release()
|
||||
self.closeSession(session, commit=False)
|
||||
|
||||
def newSMSGAddress(self, use_type=AddressTypes.RECV_OFFER, addressnote=None, session=None):
|
||||
now = int(time.time())
|
||||
|
|
|
@ -533,6 +533,56 @@ def js_identities(self, url_split, post_string: str, is_json: bool) -> bytes:
|
|||
return bytes(json.dumps(swap_client.listIdentities(filters)), 'UTF-8')
|
||||
|
||||
|
||||
def js_automationstrategies(self, url_split, post_string: str, is_json: bool) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
|
||||
filters = {
|
||||
'page_no': 1,
|
||||
'limit': PAGE_LIMIT,
|
||||
'sort_by': 'created_at',
|
||||
'sort_dir': 'desc',
|
||||
}
|
||||
|
||||
if post_string != '':
|
||||
post_data = getFormData(post_string, is_json)
|
||||
|
||||
if have_data_entry(post_data, 'sort_by'):
|
||||
sort_by = get_data_entry(post_data, 'sort_by')
|
||||
assert (sort_by in ['created_at', 'rate']), 'Invalid sort by'
|
||||
filters['sort_by'] = sort_by
|
||||
if have_data_entry(post_data, 'sort_dir'):
|
||||
sort_dir = get_data_entry(post_data, 'sort_dir')
|
||||
assert (sort_dir in ['asc', 'desc']), 'Invalid sort dir'
|
||||
filters['sort_dir'] = sort_dir
|
||||
|
||||
if have_data_entry(post_data, 'offset'):
|
||||
filters['offset'] = int(get_data_entry(post_data, 'offset'))
|
||||
if have_data_entry(post_data, 'limit'):
|
||||
filters['limit'] = int(get_data_entry(post_data, 'limit'))
|
||||
assert (filters['limit'] > 0 and filters['limit'] <= PAGE_LIMIT), 'Invalid limit'
|
||||
|
||||
if len(url_split) > 3:
|
||||
strat_id = int(url_split[3])
|
||||
strat_data = swap_client.getAutomationStrategy(strat_id)
|
||||
rv = {
|
||||
'record_id': strat_data.record_id,
|
||||
'label': strat_data.label,
|
||||
'type_ind': strat_data.type_ind,
|
||||
'only_known_identities': strat_data.only_known_identities,
|
||||
'num_concurrent': strat_data.num_concurrent,
|
||||
'data': json.loads(strat_data.data.decode('utf-8')),
|
||||
'note': '' if strat_data.note is None else strat_data.note,
|
||||
}
|
||||
return bytes(json.dumps(rv), 'UTF-8')
|
||||
|
||||
rv = []
|
||||
strats = swap_client.listAutomationStrategies(filters)
|
||||
for row in strats:
|
||||
rv.append((row[0], row[1], row[2]))
|
||||
return bytes(json.dumps(rv), 'UTF-8')
|
||||
|
||||
|
||||
def js_vacuumdb(self, url_split, post_string, is_json) -> bytes:
|
||||
swap_client = self.server.swap_client
|
||||
swap_client.checkSystemStatus()
|
||||
|
@ -647,6 +697,7 @@ pages = {
|
|||
'generatenotification': js_generatenotification,
|
||||
'notifications': js_notifications,
|
||||
'identities': js_identities,
|
||||
'automationstrategies': js_automationstrategies,
|
||||
'vacuumdb': js_vacuumdb,
|
||||
'getcoinseed': js_getcoinseed,
|
||||
'setpassword': js_setpassword,
|
||||
|
|
|
@ -160,6 +160,12 @@ class Test(BaseTest):
|
|||
assert (len(rv) == 1)
|
||||
assert (rv[0]['visibility_override'] == 1)
|
||||
|
||||
rv = read_json_api(1800, 'automationstrategies')
|
||||
assert (len(rv) == 2)
|
||||
|
||||
rv = read_json_api(1800, 'automationstrategies/1')
|
||||
assert (rv['label'] == 'Accept All')
|
||||
|
||||
def test_01_verifyrawtransaction(self):
|
||||
txn = '0200000001eb6e5c4ebba4efa32f40c7314cad456a64008e91ee30b2dd0235ab9bb67fbdbb01000000ee47304402200956933242dde94f6cf8f195a470f8d02aef21ec5c9b66c5d3871594bdb74c9d02201d7e1b440de8f4da672d689f9e37e98815fb63dbc1706353290887eb6e8f7235012103dc1b24feb32841bc2f4375da91fa97834e5983668c2a39a6b7eadb60e7033f9d205a803b28fe2f86c17db91fa99d7ed2598f79b5677ffe869de2e478c0d1c02cc7514c606382012088a8201fe90717abb84b481c2a59112414ae56ec8acc72273642ca26cc7a5812fdc8f68876a914225fbfa4cb725b75e511810ac4d6f74069bdded26703520140b27576a914207eb66b2fd6ed9924d6217efc7fa7b38dfabe666888acffffffff01e0167118020000001976a9140044e188928710cecba8311f1cf412135b98145c88ac00000000'
|
||||
prevout = {
|
||||
|
|
Loading…
Reference in a new issue