delete a transaction after it is read
This commit is contained in:
parent
7bd5e4fa8d
commit
6d5c0b6e1c
@ -10,6 +10,7 @@ from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.types import Float
|
||||
from sqlalchemy_json import MutableJson
|
||||
from sqlalchemy import and_, or_, not_
|
||||
import hashlib
|
||||
import json
|
||||
|
||||
@ -93,6 +94,25 @@ class Slate(db.Model):
|
||||
list_slates.append(slate_db.slate)
|
||||
return list_slates
|
||||
|
||||
@classmethod
|
||||
def delete_slate(cls, address, slate):
|
||||
q = cls.query
|
||||
q = q.filter(and_(Slate.receivingAddress == address, Slate.slate == slate) )
|
||||
result = q.first()
|
||||
if result is None:
|
||||
print("none guy")
|
||||
return True
|
||||
try:
|
||||
db.session.delete(result)
|
||||
db.session.commit()
|
||||
db.session.flush()
|
||||
return True
|
||||
except Exception as ex:
|
||||
db.session.rollback()
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@classmethod
|
||||
def add(cls, slate, receivingAddress):
|
||||
from funding.factory import db
|
||||
|
@ -79,3 +79,36 @@ def getSlates(receivingAddress, signature):
|
||||
except Exception as ex:
|
||||
print(f'{ex}')
|
||||
return make_response(jsonify({'status': 'failure', 'error': str(ex)}))
|
||||
|
||||
|
||||
@app.route('/deleteSlate', methods=['POST'])
|
||||
@endpoint.api(
|
||||
parameter('receivingAddress', type=str, required=True),
|
||||
parameter('signature', type=str, required=True),
|
||||
parameter('slate', type=str, required=True)
|
||||
)
|
||||
def deleteSlate(receivingAddress, signature, slate):
|
||||
try:
|
||||
if receivingAddress is None or signature is None:
|
||||
return make_response(jsonify({'status': 'failure', 'error': str("missing correct arguments")}))
|
||||
|
||||
# Deserialize the base-58 address to an internal public key format
|
||||
# NOTE: This assumes that the network version (which is not part of the key) is exactly 2 bytes
|
||||
public_key = secp256k1.PublicKey(base58.b58decode_check(receivingAddress)[2:], raw=True)
|
||||
|
||||
# Prepare the message bound to the signature: a domain separator and the encoded address
|
||||
# For some reason, the original client code calls this the "challenge"
|
||||
message = 'SubscribeRequest_' + receivingAddress
|
||||
|
||||
# Deserialize and verify the provided signature against the message and address public key
|
||||
if not public_key.ecdsa_verify(message.encode(),
|
||||
public_key.ecdsa_deserialize(bytes(bytearray.fromhex(signature)))):
|
||||
return make_response(jsonify({'status': 'failure', 'error': str("bad signature")}))
|
||||
|
||||
is_deleted = Slate.delete_slate(address=receivingAddress, slate=slate)
|
||||
|
||||
return make_response(jsonify({'status': 'success', 'is_deleted': is_deleted}))
|
||||
|
||||
except Exception as ex:
|
||||
print(f'{ex}')
|
||||
return make_response(jsonify({'status': 'failure', 'error': str(ex)}))
|
||||
|
Loading…
Reference in New Issue
Block a user