def postNewTransactions(network): """ ``POST /multisignature/{network}/post`` endpoint. Post transaction from multisignature wallet to be remotly signed:: data = {"transactions": [tx1, tx2, ... txi ..., txn]} See :func:`putSignature`. """ if network != getattr(rest.cfg, "network", False): rest.use(network) if flask.request.method == "POST": data = json.loads(flask.request.data) if "transactions" not in data: return json.dumps({ "success": False, "API error": "transaction(s) not found" }) return append(network, *data.get("transactions", [])) else: return json.dumps({ "success": False, "API error": "POST request only allowed here" })
def use(network): global LOGGED if network != flask.session.get("network", False): rest.use(network) flask.session["network"] = cfg.network Transaction.unlink() LOGGED = False return flask.redirect(flask.url_for("logout")) else: return flask.redirect(flask.url_for("account"))
def wrapper(*args, **kw): network = kw.get("network", "?") if hasattr(net, network) and \ network != getattr(rest.cfg, network, False): try: rest.use(network) except Exception: return flask.render_template("void.html", network=network) return func(*args, **kw) else: return flask.render_template("void.html", network=network)
def setUpClass(self): def fix_fixture(tx): for key in [k for k in ["amount", "fee", "nonce"] if k in tx]: tx[key] = int(tx.pop(key)) return tx self.fixtures = [ fix_fixture(tx) for tx in data.loadJson( os.path.join(os.path.abspath(os.path.dirname(__file__)), "fixtures.json")) ] rest.use("ark")
def setUpClass(self): # secrets used for testing self.secret = "secret" self.secondSecret = "secondSecret" # initialize on ark devnet if rest.use("dark"): self.wallet = dposlib.core.api.Wallet( dposlib.core.crypto.getAddress( dposlib.core.crypto.getKeys(self.secret)["publicKey"]))
def registerWallet(network): """ ``POST /multisignature/{network}/create`` endpoint. Register as multisignature wallet:: data = { "info": { "senderPublicKey": wallet_public_key_issuing_transaction, "min": minimum_signature_required, "publicKeys": public_key_list } } Once created on server, registration transaction have to be remotly signed. See :func:`putSignature`. """ if network != getattr(rest.cfg, "network", False): rest.use(network) if flask.request.method == "POST": data = json.loads(flask.request.data) if "info" not in data: return json.dumps({"error": "no info"}) tx = dposlib.core.registerMultiSignature(data["info"]["min"], *data["info"]["publicKeys"]) tx.senderPublicKey = data["info"]["senderPublicKey"] tx.useDynamicFee(data["info"].get("fee", "avgFee")) tx.setFee() return append(network, tx) else: return json.dumps({ "success": False, "API error": "POST request only allowed here" })
def getSerial(network, ms_publicKey, txid): """ ``GET /multisignature/{network}/{ms_publicKey}/{txid}/serial`` endpoint. Return specific pending transaction serial from a specific public key. """ if network != getattr(rest.cfg, "network", False): rest.use(network) if flask.request.method != "GET": return json.dumps({ "success": False, "API error": "GET request only allowed here" }) tx = load(network, ms_publicKey, txid) if tx: return json.dumps({ "success": True, "data": hexlify(crypto.getBytes(tx)) }), 200 else: return json.dumps({"success": False})
def setUpClass(self): # secrets used for testing self.secret = "secret" self.secondSecret = "secondSecret" # initialize on ark devnet rest.use("dark")
root["name"] = network root["env"] = os.path.expanduser( os.path.join(config_folder, network, ".env")) dumpJson(root, "root.json") logMsg("node configuration saved in %s" % os.path.join(JSON, "root.json")) # edit .env file to enable webhooks ENV = root["env"] env = loadEnv(ENV) env["CORE_WEBHOOKS_API_ENABLED"] = "true" env["CORE_WEBHOOKS_ENABLED"] = "true" env["CORE_WEBHOOKS_HOST"] = "0.0.0.0" env["CORE_WEBHOOKS_PORT"] = "4004" dumpEnv(env, ENV) logMsg("environement configuration saved in %s" % ENV) # initialize zen getIp() initPeers() # initialize blockchain network root = loadJson("root.json") rest.use(root.get("blockchain", "dark")) dposlib.core.stop() # customize blockchain network custom_peers = loadJson("tbw.json").get("custom_peers", []) if len(custom_peers) > 0: dposlib.rest.cfg.peers = custom_peers
ROOT = os.path.abspath(os.path.dirname(__file__)) TX_GENESIS = [] LOGGED = False # add a parser to catch the network on startup and connect to network parser = optparse.OptionParser() parser.add_option( "-n", "--network", dest="network", type="string", default="ark", metavar="NETWORK", help="Network you want to connect with [curent : %default]" ) (options, args) = parser.parse_args() rest.use(options.network) # create the application instance app = flask.Flask("DPOS wallet [%s]" % options.network) app.config.update( # 600 seconds = 10 minutes lifetime session PERMANENT_SESSION_LIFETIME = 300, # used to encrypt cookies # secret key is generated each time app is restarted SECRET_KEY = os.urandom(24), # JS can't access cookies SESSION_COOKIE_HTTPONLY = True, # bi use of https SESSION_COOKIE_SECURE = False, # update cookies on each request
def putSignature(network, ms_publicKey): """ ``PUT /multisignature/{network}/{ms_publicKey}/put`` endpoint. Add signature to a pending transaction:: data = { "info": { "id": pending_transaction_id, "signature": signature, "publicKey": associated_public_key } [ + { "fee": optional_fee_value_to_use } ] } """ if network != getattr(rest.cfg, "network", False): rest.use(network) if flask.request.method == "PUT": data = json.loads(flask.request.data) if "info" not in data: return json.dumps({"error": "no info"}) txid = data["info"]["id"] tx = load(network, ms_publicKey, txid) if not tx: return json.dumps({ "success": False, "API error": "transaction %s not found" % txid }) tx = dposlib.core.Transaction(tx) publicKey = data["info"]["publicKey"] signature = data["info"]["signature"] publicKeys = \ tx["asset"].get("multiSignature", {}).get("publicKeys", []) \ if tx["type"] == 4 else tx._multisignature.get("publicKeys", []) if publicKey not in (publicKeys + [tx._secondPublicKey, tx._publicKey]): return json.dumps({ "success": False, "API error": "public key %s not allowed here" % publicKey }) # sign type 4 # signatures field is full if tx.type == 4 and len(tx.get("signatures", [])) == len(publicKeys): if publicKey == tx._publicKey: # and signature matches type 4 issuer's public key if crypto.verifySignatureFromBytes(crypto.getBytes(tx), publicKey, signature): tx.signature = signature dump(network, tx) if tx._secondPublicKey is None: # if no need to signSign --> broadcast tx and return # network response return broadcast(network, tx) else: return json.dumps({ "success": True, "message": "issuer signature added" }) else: return json.dumps({ "success": False, "API error": "signature does not match issuer key" }) # signSign elif publicKey == tx._secondPublicKey: # if tx already signed by issuer if "signature" in tx: # and signature matches type 4 issuer 's second public key if crypto.verifySignatureFromBytes(crypto.getBytes(tx), publicKey, signature): # signSign, broadcast and return network response tx.signSignature = signature return broadcast(network, tx) else: return json.dumps({ "success": False, "API error": "signature does not match issuer " "second key" }) else: return json.dumps({ "success": False, "API error": "transaction have to be signed first" }) # verify owner signature check = crypto.verifySignatureFromBytes( crypto.getBytes(tx, exclude_sig=True, exclude_multi_sig=True, exclude_second_sig=True), publicKey, signature) # if signature matches if check and publicKey in publicKeys: index = publicKeys.index(publicKey) # set is used here to remove doubles tx["signatures"] = list( set(tx.get("signatures", []) + ["%02x" % index + signature])) if tx["type"] != 4 and \ len(tx.get("signatures", [])) >= tx._multisignature["min"]: return broadcast(network, tx) else: dump(network, tx) return json.dumps({ "success": True, "message": "signature added to transaction", }), 201 else: return json.dumps({ "success": False, "API error": "signature not accepted" }) else: return json.dumps({ "success": False, "API error": "PUT request only allowed here" })