def get_available_assets(): #Load the mapping object req = requests.get( 'https://s3.eu-west-1.amazonaws.com/gtsa-mapping/map.json') s3 = boto3.resource('s3') s3.Bucket('gtsa-mapping').download_file('rassets.json', 'rassets.json') req_ra = requests.get( 'https://s3.eu-west-1.amazonaws.com/gtsa-mapping/rassets.json') map_obj = am.MapDB(2, 3) map_obj.init_json(req.json()) #load the controller public keys con_keys = am.ConPubKey() con_keys.load_json('controllers.json') key_list = con_keys.list_keys() if not map_obj.verify_multisig(key_list): print("Signature verification failed") r_obj = req_ra.json() chaininfo = ocean.call('getblockchaininfo') blkh = int(chaininfo["blocks"]) token_ratio = round(am.token_ratio(blkh), 13) available_assets = [] for asset in r_obj["assets"]: available_asset = {} ref = asset["ref"] lck = asset["lock"] if not lck: mass = map_obj.get_mass_assetid(ref) exptoken = am.token_amount(blkh, mass) ref_comp = ref.split("-") available_asset["serialno"] = ref_comp[0] available_asset["year"] = ref_comp[1] available_asset["manufacturer"] = ref_comp[2] available_asset["mass"] = mass available_asset["tokens"] = exptoken available_assets.append(available_asset) return blkh, token_ratio, available_assets
print(" ") rref = assetRef + "-" + assetYear + "-" + assetMan print("Redemption of asset: " + rref) print(" ") if assetMass != map_obj.get_mass_assetid(rref): print("ERROR: total mass of asset " + rref + " in object = " + str("%.8f" % map_obj.get_mass_assetid(rref))) print("Exit") sys.exit() chaininfo = ocean.call('getblockchaininfo') print(" Current blockheight: " + str(chaininfo["blocks"])) token_ratio = am.token_ratio(int(chaininfo["blocks"])) print(" Current token ratio = " + str("%.13f" % token_ratio)) print(" ") inpt = input("Enter the redemption initiation block height: ") blkh = int(inpt) print(" ") red_token_ratio = am.token_ratio(blkh) tokenAmount = assetMass / red_token_ratio print(" Token ratio: " + str("%.13f" % red_token_ratio) + " at height " + str(blkh)) print(" Required total tokens: " + str("%.8f" % round(assetMass / red_token_ratio, 8))) print(" ") inpt = input("Enter total number of burnt token types: ")
datetime.fromtimestamp(bestblock["time"]).strftime('%c') + ")") print(" System time: " + str(datetime.now().timestamp()) + " (" + datetime.now().strftime('%c') + ")") print(" ") if datetime.now().timestamp() > float(bestblock["time"]) + 100.0: print("ERROR: best block time more than 1 minute in the past") print("Check syncronisation of system clock, then contact system admin") print("Exit") sys.exit() print(" ") print("Confirm token issuances:") print(" ") bheight = chaininfo["blocks"] token_ratio = am.token_ratio(bheight) print(" token ratio = " + str("%.13f" % round(token_ratio, 13))) print(" ") numiss = int(partial_tx["numiss"]) for issit in range(numiss): tokenAmount = am.token_amount(bheight, partial_tx[str(issit)]["mass"]) decode_tx = ocean.call('decoderawtransaction', partial_tx[str(issit)]["hex"]) txTokenAmount = decode_tx["vin"][0]["issuance"]["assetamount"] print(" mass = " + str("%.3f" % partial_tx[str(issit)]["mass"]) + " expected tokens = " + str("%.8f" % round(tokenAmount, 8)) + " transaction tokens = " + str("%.8f" % txTokenAmount)) if round(tokenAmount, 8) != round(txTokenAmount, 8): print("ERROR: Issuance amount in transaction is incorrect")
print(" ") rref = assetRef+"-"+assetYear+"-"+assetMan print("Redemption of asset: "+rref) print(" ") if assetMass != map_obj.get_mass_assetid(rref): print("ERROR: total mass of asset "+rref+" in object = "+str("%.3f" % map_obj.get_mass_assetid(rref))) print("Exit") sys.exit() inpt = input("Enter the redemption initiation block height: ") blkh = int(inpt) print(" ") token_ratio = am.token_ratio(blkh) tokenAmount = assetMass/token_ratio print(" Token ratio: "+str("%.13f" % token_ratio)+" at height "+str(blkh)) print(" Required total tokens: "+str("%.8f" % round(assetMass/token_ratio,8))) print(" ") inpt = input("Enter total number of burnt token types: ") ntokens = int(inpt) if ntokens < 1: print("ERROR: must have one or more tokens types to redeem") print("Exit") sys.exit() burnt_tokens = [] for itt in range(ntokens): btoken = [] print(" Burnt token "+str(itt)+": ")
def redemption_check(rref, rfeetx, rtx): # hard-coded address for the redemption fee and the required amount fAddress = "12tkJYZGHAbMprRPGwHGKtVFPMydND9waZ" rfee = 5.0 #Load the mapping object - connecting to S3 req = requests.get( 'https://s3.eu-west-1.amazonaws.com/gtsa-mapping/map.json') map_obj = am.MapDB(2, 3) map_obj.init_json(req.json()) #load the controller public keys con_keys = am.ConPubKey() con_keys.load_json('controllers.json') key_list = con_keys.list_keys() if not map_obj.verify_multisig(key_list): return False, "Signature verification failed" s3 = boto3.resource('s3') s3.Bucket('gtsa-mapping').download_file('rassets.json', 'rassets.json') # Load the redeem list object - rassets.json with open('rassets.json') as file: r_obj = json.load(file) chaininfo = ocean.call('getblockchaininfo') blkh = int(chaininfo["blocks"]) token_ratio = am.token_ratio(blkh) rmass = map_obj.get_mass_assetid(rref) if rmass < 0.1: return False, "Invalid asset reference" inlist = 0 locked = False for asst in r_obj["assets"]: if asst["ref"] == rref: inlist = 1 locked = asst["lock"] if inlist == 0: return False, "Asset reference not in the redeemable asset list" if locked: return False, "Entered asset already locked for redemption" # expect number of tokens for redemption exptoken = am.token_amount(blkh, rmass) feetxcheck = ocean.call('testmempoolaccept', rfeetx) if feetxcheck["allowed"] == 0: return False, "Fee transaction invalid " + feetxcheck["reject-reason"] feedecode = ocean.call('decoderawtransaction', rfeetx) feetotal = 0.0 for outs in feedecode["vout"]: if outs["scriptPubKey"]["type"] == "pubkeyhash": if outs["scriptPubKey"]["addresses"][0] == fAddress: feetotal += outs["value"] if feetotal < rfee: return False, "Fee transaction total tokens: " + str( feetotal) + " is insufficient" rtxcheck = ocean.call('testmempoolaccept', rtx) if rtxcheck["allowed"] == 0: return False, "Redemption transaction invalid " + rtxcheck[ "reject-reason"] rdecode = ocean.call('decoderawtransaction', rtx) frztag = 0 tokentotal = 0.0 rAddresses = [] rAssets = [] for outs in rdecode["vout"]: if map_obj.get_mass_tokenid(outs["asset"]) < 0.1: return False, "ERROR: redemption transaction contains an un-mapped token" if outs["n"] == 0: if outs["scriptPubKey"]["addresses"][ 0] == "2dZRkPX3hrPtuBrmMkbGtxTxsuYYgAaFrXZ": frztag = 1 else: if outs["scriptPubKey"]["type"] == "pubkeyhash": tokentotal += outs["value"] addrs = outs["scriptPubKey"]["addresses"][0] rAddresses.append(addrs) outasset = outs["asset"] rAssets.append(outasset) if frztag == 0: return False, "Transaction is not a redemption transaction" if tokentotal < round(exptoken, 6): return False, "Redemption transaction total tokens: " + str( feetotal) + " is insufficient" return True, "ALL REDEMPTION CHECKS PASSED"
def __init__(self, parent=None): super(TokenDialog, self).__init__(parent) rpcport = 8332 rpcuser = '******' rpcpassword = '******' url = 'http://' + rpcuser + ':' + rpcpassword + '@localhost:' + str( rpcport) ocean = rpc.RPCHost(url) utxorep = ocean.call('getutxoassetinfo') token_ratio, hour = am.token_ratio() s3 = boto3.resource('s3') s3.Bucket('gtsa-mapping').download_file('map.json', 'map.json') self.setWindowTitle("Token Report") self.left = 10 self.top = 10 self.width = 720 self.height = 500 self.setGeometry(self.left, self.top, self.width, self.height) self.tokenReport = QGroupBox("Blockchain token analysis: UTXO scan") self.tokenView = QTreeView() self.tokenView.setRootIsDecorated(False) self.tokenView.setAlternatingRowColors(True) tokenLayout = QHBoxLayout() tokenLayout.addWidget(self.tokenView) self.tokenReport.setLayout(tokenLayout) self.tokenModel = self.createReportModel(self) self.tokenView.setModel(self.tokenModel) self.tokenView.setColumnWidth(0, 200) self.tokenRatio = QLabel("Token ratio: " + str("%.8f" % token_ratio) + " oz/token at hour " + str(hour)) map_obj = am.MapDB(2, 3) map_obj.load_json('map.json') json_obj = map_obj.get_json() for entry in utxorep: asset = entry["asset"] amount = entry["amountspendable"] + entry["amountfrozen"] mass = 0.0 inmap = False for i, j in json_obj["assets"].items(): if j["tokenid"] == asset: mass += j["mass"] inmap = True if inmap and amount < 9.0: exptoken = mass / token_ratio self.addReport(self.tokenModel, asset, mass, exptoken, amount) layout = QVBoxLayout() layout.addWidget(self.tokenReport) layout.addWidget(self.tokenRatio) self.setLayout(layout)