Skip to content
Snippets Groups Projects
Commit 91e56624 authored by alexey.stratulat's avatar alexey.stratulat Committed by Roman Khlopkov
Browse files

The wrapper from the wizard for working with orders has been moved. And...

The wrapper from the wizard for working with orders has been moved. And converted statics to globals
parent 05ce7d5e
No related branches found
No related tags found
1 merge request!95The wrapper from the wizard for working with orders has been moved. And converted statics to globals
Showing
with 295 additions and 4 deletions
......@@ -373,8 +373,8 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){
PyType_Ready( &ServerCore_ServerCoreType ) < 0 ||
PyType_Ready( &dapEvents_dapEventsType ) < 0 ||
PyType_Ready( &dapEventsSocket_dapEventsSocketType ) < 0 ||
PyType_Ready( &CryptoKeyTypeObjecy_CryptoKeyTypeObjecyType ) < 0 ||
PyType_Ready( &CryptoDataTypeObjecy_CryptoDataTypeObjecyType ) < 0 ||
PyType_Ready( &CryptoKeyTypeObject_CryptoKeyTypeObjectType ) < 0 ||
PyType_Ready( &CryptoDataTypeObject_CryptoDataTypeObjectType ) < 0 ||
PyType_Ready(&DapSignObject_DapSignObjectType) < 0 ||
PyType_Ready(&DapSignTypeObject_DapSignTypeObjectType) < 0 ||
// === Chain ===
......@@ -427,6 +427,11 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){
PyType_Ready(&DapChainNetSrvObject_DapChainNetSrvObjectType) < 0 ||
PyType_Ready(&DapChainNetSrvClientObject_DapChainNetSrvClientObjectType) < 0 ||
PyType_Ready(&DapChainNetSrvDatumObject_DapChainNetSrvDatumObjectType) < 0 ||
PyType_Ready(&DapChainNetSrvOrderDirectionObject_DapChainNetSrvOrderDirectionObjectType) < 0 ||
PyType_Ready(&DapChainNetSrvOrderObject_DapChainNetSrvOrderObjectType) < 0 ||
PyType_Ready(&DapChainNetSrvUIDObject_DapChainNetSrvUIDObjectType) < 0 ||
PyType_Ready(&DapChainNetSrvPriceObject_DapChainNetSrvPriceObjectType) < 0 ||
PyType_Ready(&DapChainNetSrvPriceUnitUIDObject_DapChainNetSrvPriceUnitUIDObjectType) < 0 ||
// =============
PyType_Ready(&DapChainGDBObject_DapChainGDBType) < 0 ||
......@@ -480,8 +485,8 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){
PyModule_AddObject(module, "Events", (PyObject*)&dapEvents_dapEventsType);
PyModule_AddObject(module, "EventsSocket", (PyObject*)&dapEventsSocket_dapEventsSocketType);
PyModule_AddObject(module, "CryptoKeyType", (PyObject*)&CryptoKeyTypeObjecy_CryptoKeyTypeObjecyType);
PyModule_AddObject(module, "CryptoDataType", (PyObject*)&CryptoDataTypeObjecy_CryptoDataTypeObjecyType);
PyModule_AddObject(module, "CryptoKeyType", (PyObject*)&CryptoKeyTypeObject_CryptoKeyTypeObjectType);
PyModule_AddObject(module, "CryptoDataType", (PyObject*)&CryptoDataTypeObject_CryptoDataTypeObjectType);
// === Chain ===
PyModule_AddObject(module, "Chain", (PyObject*)&dapChainObject_dapChainType);
......@@ -533,6 +538,11 @@ PyMODINIT_FUNC PyInit_libCellFrame(void){
PyModule_AddObject(module, "ChainNetSrv", (PyObject*)&DapChainNetSrvObject_DapChainNetSrvObjectType);
PyModule_AddObject(module, "ChainNetSrvClient", (PyObject*)&DapChainNetSrvClientObject_DapChainNetSrvClientObjectType);
PyModule_AddObject(module, "ChainNetSrvDatum", (PyObject*)&DapChainNetSrvDatumObject_DapChainNetSrvDatumObjectType);
PyModule_AddObject(module , "ChainNetSrvPrice", (PyObject*)&DapChainNetSrvPriceObject_DapChainNetSrvPriceObjectType);
PyModule_AddObject(module, "ChainNetSrvOrder", (PyObject*)&DapChainNetSrvOrderObject_DapChainNetSrvOrderObjectType);
PyModule_AddObject(module, "ChainNetSrvOrderDirection", (PyObject*)&DapChainNetSrvOrderDirectionObject_DapChainNetSrvOrderDirectionObjectType);
PyModule_AddObject(module, "ChainNetSrvUID", (PyObject*)&DapChainNetSrvUIDObject_DapChainNetSrvUIDObjectType);
PyModule_AddObject(module, "ChainNetSrvPriceUnitUID", (PyObject*)&DapChainNetSrvPriceUnitUIDObject_DapChainNetSrvPriceUnitUIDObjectType);
// =============
PyModule_AddObject(module, "ChainGDB", (PyObject*)&DapChainGDBObject_DapChainGDBType);
......
......@@ -7,4 +7,39 @@ PyObject *dap_chain_mempool_add_proc_py(PyObject *self, PyObject *args){
return NULL;
dap_chain_mempool_add_proc(DAP_HTTP(((PyDapServerObject*)obj_server)->t_server), MEMPOOL_URL);
return PyLong_FromLong(0);
}
PyObject *dap_chain_mempool_tx_create_py(PyObject *self, PyObject *args){
(void)self;
PyObject *obj_chain;
PyObject *obj_key_from;
PyObject *obj_addr_from;
PyObject *obj_addr_to;
PyObject *obj_addr_fee;
char *l_token_ticker;
uint64_t l_value;
uint64_t l_value_fee;
if (!PyArg_ParseTuple(args, "OOOOOskk", &obj_chain, &obj_key_from, &obj_addr_from, &obj_addr_to, &obj_addr_fee,
&l_token_ticker, &l_value, &l_value_fee)){
return NULL;
}
dap_chain_t *l_chain = ((PyDapChainObject*)obj_chain)->chain_t;
dap_enc_key_t *l_key_from = ((PyCryptoKeyObject*)obj_key_from)->key;
dap_chain_addr_t *l_addr_from = ((PyDapChainAddrObject*)obj_addr_from)->addr;
dap_chain_addr_t *l_addr_to = ((PyDapChainAddrObject*)obj_addr_to)->addr;
dap_chain_addr_t *l_addr_fee = ((PyDapChainAddrObject*)obj_addr_fee)->addr;
uint256_t l_value_256 = dap_chain_uint256_from(l_value);
uint256_t l_value_fee_256 = dap_chain_uint256_from(l_value_fee);
dap_chain_hash_fast_t *l_hash_tx = dap_chain_mempool_tx_create(l_chain, l_key_from,
l_addr_from, l_addr_to,
l_addr_fee, l_token_ticker,
l_value_256, l_value_fee_256);
if (l_hash_tx == NULL){
return Py_None;
} else {
PyDapHashFastObject *obj_hf = PyObject_New(PyDapHashFastObject, &DapHashFastObject_DapHashFastObjectType);
PyObject_Dir((PyObject*)obj_hf);
obj_hf->hash_fast = l_hash_tx;
return (PyObject*)obj_hf;
}
}
\ No newline at end of file
File added
from API_CellFrame import logItNotice, AppCliServer
"""
This function takes two arguments
argv is an array of incoming arguments
indexStrReply is an internal index that correlates what is needed
to fill the desired buffer with the data that will be passed to the CLI.
"""
def cmdDemo(argv, indexStrReply):
reply = "Arguments :\n"
for i in range(len(argv)):
reply += "arg["+str(i)+"]: "+argv[i]+"\n"
AppCliServer.setReplyText(reply, indexStrReply)
def cmdDemo2(argv, indexStrReply):
AppCliServer.setReplyText("I simple demo command", indexStrReply)
def init():
logItNotice("Running plugin order")
"""
The cmdItemCreate function creates a CLI command.
This function takes four arguments.
Command name, command handler function, short description of
of the command, full description of the command.
"""
AppCliServer.cmdItemCreate("demo", cmdDemo, "Command demo",
"""
This command is intended to demonstrate the work of custom command in the CellFrame API for Python.
""")
AppCliServer.cmdItemCreate("demo2", cmdDemo2, "Second command demo",
"""
This is demo and testing
""")
return 0
{
"name": "demoCustomCMD",
"version": "1.0",
"author": "DEMLABS (C) 2022",
"dependencys": [],
"description": "This is a plugin example for working custom command."
}
from API_CellFrame import logItNotice, ChainNetSrvOrder, ChainNet, ChainNetSrvUID, ChainNetSrvOrderDirection, ChainNetSrvPriceUnitUID
from API_CellFrame import Crypto, CryptoKeyType, AppCliServer, ChainHashFast
import time
from datetime import datetime, timedelta
def infoOrder(order):
# hash = ChainHashFast.strToHashFast(hash_str)
# order = ChainNetSrvOrder.find(net, hash_str)
reply = "Order: \n"
reply += "\tVersion:" + str(order.version)+"\n"
reply += "\tUID: " + str(order.uid) + "\n"
reply += "\tDirection: " + str(order.direction) + "\n"
reply += "\tNode addr: " + str(order.nodeAddr) + "\n"
reply += "\tCond hash: " + str(order.condHash) + "\n"
reply += "\tPrice unit: " + str(order.priceUnit) + "\n"
created = datetime.fromtimestamp(order.tsCreated)
reply += "\tCreated: " + str(created) + "\n"
expires = datetime.fromtimestamp(order.tsExpires)
reply += "\tExpires: " + str(expires) + "\n"
reply += "\tSrv price: " + str(order.srvPrice) + "\n"
reply += "\tSrv price ticker: " + order.srvPriceTicker + "\n"
reply += "\textSignSize:" + str(order.extSize) + "\n"
reply += "\tSignature:\n"
sign = order.extSign
if sign is None:
reply += "Signature none"
else:
type = sign.type
pkey = sign.pkey
pkey_type = pkey.type
# pkey_hash = pkey.hash
pkey_size = pkey.size
pkey_dict = {
'type': str(pkey_type),
'size': pkey_size
}
pkey_hash = sign.pkeyHash
sig_dict = {
'type': str(sign.type),
'pkey': pkey_dict,
'pkey_hash': str(pkey_hash),
'size': str(sign.size)
}
reply += str(sig_dict)
# reply += "\Signs:" + str(order.ext) + "\n"
return reply
def pwoCMD(argv, indexStrReply):
print(indexStrReply)
if (len(argv) == 5):
net = ChainNet.byName(argv[2])
if argv[3] == "find":
order = ChainNetSrvOrder.find(net, argv[4])
reply = ""
if order is None:
reply = "Order with hash "+argv[4]+" not fined."
else:
reply = "Order: \n"
order_reply = infoOrder(order)
reply += order_reply
# reply += "\tVersion:" + str(order.version)+"\n"
# reply += "\tUID: " + str(order.uid) + "\n"
# reply += "\tDirection: " + str(order.direction) + "\n"
# reply += "\tNode addr: " + str(order.nodeAddr) + "\n"
## reply += "\tCond hash: " + str(order.condHash) + "\n"
# reply += "\tPrice unit: " + str(order.priceUnit) + "\n"
# created = datetime.fromtimestamp(order.tsCreated)
# reply += "\tCreated: " + str(created) + "\n"
# expires = datetime.fromtimestamp(order.tsExpires)
# reply += "\tExpires: " + str(expires) + "\n"
# reply += "\tSrv price: " + str(order.srvPrice) + "\n"
# reply += "\tSrv price ticker: " + order.srvPriceTicker + "\n"
# reply += "\text size:" + str(order.extSize) + "\n"
# reply += "\text:" + str(order.ext) + "\n"
AppCliServer.setReplyText(reply, indexStrReply)
elif argv[3] == "del":
res = ChainNetSrvOrder.delete(net, argv[4])
AppCliServer.setReplyText("Result: "+str(res)+".", indexStrReply)
else:
AppCliServer.setReplyText("An unknown action is specified to be performerd on the order.", indexStrReply)
else:
AppCliServer.setReplyText("This command takes only four arguments.", indexStrReply)
def infoCMD(argv, indexStrReply):
if (len(argv) == 2):
hash = ChainHashFast.strToHashFast(argv[1])
order = ChainNetSrvOrder.find(hash)
reply = "Order: \n"
order_reply = infoOrder(order)
reply += order_reply
# reply += "\tVersion:" + str(order.version)+"\n"
# reply += "\tUID: " + str(order.uid) + "\n"
# reply += "\tDirection: " + str(order.direction) + "\n"
# reply += "\tNode addr: " + str(order.nodeAddr) + "\n"
# reply += "\tCond hash: " + str(order.condHash) + "\n"
# reply += "\tPrice unit: " + str(order.priceUnit) + "\n"
# created = datetime.fromtimestamp(order.tsCreated)
# reply += "\tCreated: " + str(created) + "\n"
# expires = datetime.fromtimestamp(order.tsExpires)
# reply += "\tExpires: " + str(expires) + "\n"
# reply += "\tSrv price: " + str(order.srvPrice) + "\n"
# reply += "\tSrv price ticker: " + order.srvPriceTicker + "\n"
# reply += "\text size:" + str(order.extSize) + "\n"
# reply += "\text:" + str(order.ext) + "\n"
AppCliServer.setReplyText(reply, indexStrReply)
else:
AppCliServer.setReplyText("Order hash not set", indexStrReply)
"""
"""
def create_key():
return Crypto.generateNewKey(CryptoKeyType.DAP_ENC_KEY_TYPE_SIG_BLISS(), "SARON00151454_VDGTKHJFY", 512, " I SIMPKLE SEED STRING ")
def order_notify(op_code, group, key, order):
print("Notify: \n")
print("op_code: "+op_code+"\n")
print("group: "+group+"\n")
print("key: "+key+"\n")
if order is not None:
print(infoOrder(order))
else:
print("No order.")
def init():
logItNotice("Running plugin order")
net = ChainNet.byName("kelvin-testnet")
#Getting info
ChainNetSrvOrder.addNotify(net, order_notify)
gdb_group = ChainNetSrvOrder.getGdbGroup(net)
logItNotice("Ordr in group: "+gdb_group)
node_list_group = ChainNetSrvOrder.getNodelistGroup(net)
logItNotice("Node list group: "+node_list_group)
#Create order
print("net: "+ str(net))
net_srv = ChainNetSrvUID(12345)
direction = ChainNetSrvOrderDirection.getDirSell()
print("direction" + str(direction))
node_addr = net.getCurAddr()
tx_cond = "TXCOND"
price = 531
priceUnitUid = ChainNetSrvPriceUnitUID.mb()
print ("Price Unit UID:" + str(priceUnitUid))
key = create_key()
#Expires
dt_exp = datetime.now()
dt_delta = timedelta(days = 30)
dt_exp += dt_delta
print (dt_exp)
print (dt_exp.timestamp())
ts_expires = dt_exp.timestamp()
print(type(ts_expires))
order = ChainNetSrvOrder(net, direction, net_srv, node_addr, None, 100, priceUnitUid, "tCELL", ts_expires, "http://myvi.com/?QBS".encode('utf-8'), key)
hash = order.save(net)
logItNotice("HASH order:"+str(hash))
AppCliServer.cmdItemCreate("pwo", pwoCMD, "Example command for working with orders through the plugin",
"""
Arguments for command:
net <net> find <hash order>
net <net> del <hash order>
""")
return 0
#def deinit():
# logItNotice("Plugin client deinit")
{
"name": "demoOrder",
"version": "1.0",
"author": "DEMLABS (C) 2022",
"dependencys": [],
"description": "This is a plugin with examples for working with orders."
}
File added
from API_CellFrame import Mempool, ChainWallet, logItNotice, configGetItem, ChainNet, ChainAddr
def init():
wallet_path = configGetItem("resources", "wallets_path")
logItNotice("wallet path: "+wallet_path)
wallet = ChainWallet.open("mywallet1", wallet_path)
chain_net = ChainNet.byName("subzero")
chain = chain_net.getChainByName("support")
key = wallet.getKey(0)
addr_from = wallet.getAddr(chain_net.id)
addr_to = ChainAddr.fromStr("mJUUJk6Yk2gBSTjcCmbwJ2ozjDTLPKZTmTVM9AUysMfWt4oQcNwjtCNEbkGo1dWVmkNXaQYbPtMqdHD4ftF5Sfx4mo9ss9r4jauSXDhV")
addr_fee = None
value = 50000
value_fee = 0
# tx_hash = Mempool.txCreate(chain, key, addr_from, addr_to, addr_fee, "tCELL", value, value_fee)
# tx_hash_str = str(tx_hash)
# print(tx_hash_str)
# logItNotice("Created transaction with hash: " + tx_hash_str)
return 0
{
"name": "exampleCreateTx",
"version": "1.0",
"author": "DEMLABS (C) 2022",
"dependencys": [],
"description": "This plugin is an example of a service plugin."
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment