def staffAccount(id): id = convert(int, id) form = forms.StaffStatusForm() if form.validate_on_submit(): return Account(id).staff(form.staff.data).serialize() else: raise MissingFieldsError(form.errors.keys())
def editAccount(id): id = convert(int, id) form = forms.AccountEditionForm() if form.validate_on_submit(): fields = {'firstname' : form.firstname.data, 'lastname' : form.lastname.data, 'promo' : form.promo.data} return Account(id=id).edit(fields).serialize() else: raise MissingFieldsError(form.errors.keys())
def test_deserialize_on_valid_tx(self): # test convert real bitcoin tx https://blockchain.info/tx-index/b6f6991d03df0e2e04dafffcd6bc418aac66049e2cd74b80f14ac86db1e3f0da?format=hex tx_hex = '010000000101820e2169131a77976cf204ce28685e49a6d2278861c33b6241ba3ae3e0a49f020000008b48304502210098a2851420e4daba656fd79cb60cb565bd7218b6b117fda9a512ffbf17f8f178022005c61f31fef3ce3f906eb672e05b65f506045a65a80431b5eaf28e0999266993014104f0f86fa57c424deb160d0fc7693f13fce5ed6542c29483c51953e4fa87ebf247487ed79b1ddcf3de66b182217fcaf3fcef3fcb44737eb93b1fcb8927ebecea26ffffffff02805cd705000000001976a91429d6a3540acfa0a950bef2bfdc75cd51c24390fd88ac80841e00000000001976a91417b5038a413f5c5ee288caa64cfab35a0c01914e88ac00000000' correct_result = '{"ins":[{"outpoint":{"hash":"9fa4e0e33aba41623bc3618827d2a6495e6828ce04f26c97771a1369210e8201","index":2},"script":"48304502210098a2851420e4daba656fd79cb60cb565bd7218b6b117fda9a512ffbf17f8f178022005c61f31fef3ce3f906eb672e05b65f506045a65a80431b5eaf28e0999266993014104f0f86fa57c424deb160d0fc7693f13fce5ed6542c29483c51953e4fa87ebf247487ed79b1ddcf3de66b182217fcaf3fcef3fcb44737eb93b1fcb8927ebecea26","sequence":4294967295}],"locktime":0,"outs":[{"script":"76a91429d6a3540acfa0a950bef2bfdc75cd51c24390fd88ac","value":98000000},{"script":"76a91417b5038a413f5c5ee288caa64cfab35a0c01914e88ac","value":2000000}],"version":1}' tx_json = convert(tx_hex, is_compact=True) self.assertEqual(tx_json, correct_result)
def parse_response(response: str) -> dict: """ Parses the response from the API and returns dictionary with converted fields. """ res = json.loads(response) return dict(id=res["id"], username=res["username"], about=convert(res["about"]), karma=int(res["karma"]), avg=res["avg"], delay=res["avg"], submitted=res["submitted"], updated_at=res["updated_at"], submission_count=res["submission_count"], comment_count=res["comment_count"], created_at_i=res["created_at_i"], object_id=res["objectID"])
def userRemove(id): id = convert(int, id) if id == current_user.get_id(): raise ApiError("You can't delete your own account.") return User(id).remove().serialize()
def revokeTransaction(id): id = convert(int, id) return Transaction(id).revoke().serialize()
def calculateBalance(id): id = convert(int, id) return {'balance' : str(Transaction.calculateBalance(id))}
def getBalance(id): id = convert(int, id) return {'balance' : str(Transaction.getBalance(id))}
def deleteAccount(id): id = convert(int, id) return Account(id=id).delete().serialize()
def getAccountByNumber(number): number = convert(int, number) return Account.getByNumber(number).serialize()
def getAccount(account_id): account_id = convert(int, account_id) return Account.get(account_id).serialize()
#!/usr/bin/python import sys from common import convert # read HEX from stdin tx_hex = sys.stdin.read() # convert to JSON tx_json = convert(tx_hex) # conversion failed if (tx_json is None): sys.stderr.write('HEX -> JSON conversion failed\n') exit(1) # success, send formatted version to stdout print tx_json