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
import json import os print("Redemption of tokens for a specified asset") print(" ") print("Controller 2: Confirmer") print(" ") print("Load the current mapping object - connecting to S3") s3 = boto3.resource('s3') s3.Bucket('gtsa-mapping').download_file('map.json', 'map.json') s3.Bucket('gtsa-mapping').download_file('/Volumes/DGLD-SIGN/map_ps.json', '/Volumes/DGLD-SIGN/map_ps.json') map_obj = am.MapDB(2, 3) map_obj.load_json('map.json') fmass = map_obj.get_total_mass() print(" Total mass: " + str("%.3f" % fmass)) print(" Timestamp: " + str(map_obj.get_time()) + " (" + datetime.fromtimestamp(map_obj.get_time()).strftime('%c') + ")") con_keys = am.ConPubKey() con_keys.load_json('controllers.json') key_list = con_keys.list_keys() if map_obj.verify_multisig(key_list): print(" Signatures verified") else: print(" Verification failed") print(" ") print("Load the updated mapping object from file")
#!/usr/bin/env python import amap.mapping as am import pybitcointools as bc print("Load the mapping object") map_obj = am.MapDB(2, 3) map_obj.load_json('map.json') map_obj.print_json() print("Read in controller private keys from file") c1_privkey = open('c1_privkey.dat', 'r').read() c2_privkey = open('c2_privkey.dat', 'r').read() c3_privkey = open('c3_privkey.dat', 'r').read() print("Update time-stamp") map_obj.update_time() map_obj.print_json() print("Add controller 1 signature") map_obj.sign_db(c1_privkey, 1) print("Add controller 3 signature") map_obj.sign_db(c3_privkey, 3) map_obj.print_json()
import boto3 import sys import json print("Redemption of tokens for a specified asset") print(" ") print("Controller 2: Confirmer") print(" ") print("Load the current mapping object - connecting to S3") s3 = boto3.resource('s3') s3.Bucket('gtsa-mapping').download_file('map.json','map.json') s3.Bucket('gtsa-mapping').download_file('ps1_map.json','ps1_map.json') map_obj = am.MapDB(2,3) map_obj.load_json('map.json') fmass = map_obj.get_total_mass() print(" Total mass: "+str("%.3f" % fmass)) print(" Timestamp: "+str(map_obj.get_time())+" ("+datetime.fromtimestamp(map_obj.get_time()).strftime('%c')+")") con_keys = am.ConPubKey() con_keys.load_json('controllers.json') key_list = con_keys.list_keys() if map_obj.verify_multisig(key_list): print(" Signatures verified") else: print(" Verification failed") print(" ") print("Load the updated mapping object from file") new_map_obj = am.MapDB(2,3)
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)
def __init__(self, parent=None): super(AMapping, self).__init__(parent) self.new_map = am.MapDB(2, 3) self.old_map = am.MapDB(2, 3) self.con_pubkeys = am.ConPubKey() self.title = 'Asset Mapping Interface' self.left = 10 self.top = 10 self.width = 1000 self.height = 540 self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) self.oldMapping = QGroupBox("Current Mapping") self.oldMapView = QTreeView() self.oldMapView.setRootIsDecorated(False) self.oldMapView.setAlternatingRowColors(True) oldMapLayout = QHBoxLayout() oldMapLayout.addWidget(self.oldMapView) self.oldMapping.setLayout(oldMapLayout) self.oldModel = self.createMapModel(self) self.oldMapView.setModel(self.oldModel) self.newMapping = QGroupBox("New Mapping") self.newMapView = QTreeView() self.newMapView.setRootIsDecorated(False) self.newMapView.setAlternatingRowColors(True) newMapLayout = QHBoxLayout() newMapLayout.addWidget(self.newMapView) self.newMapping.setLayout(newMapLayout) self.newModel = self.createMapModel(self) self.newMapView.setModel(self.newModel) self.oldMapView.setColumnWidth(0, 50) self.newMapView.setColumnWidth(0, 50) self.issueButton = QPushButton("&Issue Asset") self.issueButton.show() self.addButton = QPushButton("&Add Asset") self.addButton.show() self.removeButton = QPushButton("&Remove Asset") self.removeButton.show() self.findButton = QPushButton("&Find Asset") self.findButton.show() self.tokenButton = QPushButton("&Token Report") self.tokenButton.show() self.remapButton = QPushButton("&Redemeption") self.remapButton.show() self.oldMassButton = QPushButton("&Mass Check") self.oldMassButton.show() self.loadOldButton = QPushButton("&Load File") self.loadOldButton.show() self.downloadButton = QPushButton("&Download") self.downloadButton.show() self.newMassButton = QPushButton("&Mass Check") self.newMassButton.show() self.loadNewButton = QPushButton("&Load File") self.loadNewButton.show() self.uploadButton = QPushButton("&Upload") self.uploadButton.show() self.sigButton = QPushButton("&Signatures") self.sigButton.show() self.saveButton = QPushButton("&Save JSON") self.saveButton.setToolTip("Save JSON to a file") self.saveButton.show() self.settingsButton = QPushButton("&Settings") self.settingsButton.setToolTip("Settings and configuration options") self.settingsButton.show() # self.dialog = IssueAssetDialog() self.addAssetDlog = AddAssetDialog() self.tokenDlog = TokenDialog() # self.dialog = SignaturesDialog() # self.dialog = RemapDialog() # self.dialog = OldMassDialog() # self.dialog = NewMassDialog() self.oldMapMass = QLabel("Mass:") self.oldMapTime = QLabel("Time:") self.oldMapSigs = QLabel("Signatures:") self.newMapMass = QLabel("Mass:") self.newMapTime = QLabel("Time:") self.newMapSigs = QLabel("Signatures:") self.conStatus = QLabel("Ocean:") self.issueButton.clicked.connect(self.issueAsset) self.addButton.clicked.connect(self.addAsset) self.removeButton.clicked.connect(self.removeAsset) self.findButton.clicked.connect(self.findAsset) self.tokenButton.clicked.connect(self.tokenReport) self.remapButton.clicked.connect(self.remapAssets) self.oldMassButton.clicked.connect(self.oldMassAsset) self.loadOldButton.clicked.connect(self.loadOldMap) self.downloadButton.clicked.connect(self.downloadMap) self.newMassButton.clicked.connect(self.newMassAsset) self.loadNewButton.clicked.connect(self.loadNewMap) self.uploadButton.clicked.connect(self.uploadMap) self.sigButton.clicked.connect(self.signatures) self.saveButton.clicked.connect(self.saveMap) self.settingsButton.clicked.connect(self.settings) buttonLayout1 = QVBoxLayout() buttonLayout1.addWidget(self.issueButton) buttonLayout1.addWidget(self.addButton) buttonLayout1.addWidget(self.removeButton) buttonLayout1.addWidget(self.findButton) buttonLayout1.addWidget(self.tokenButton) buttonLayout1.addWidget(self.remapButton) buttonLayout1.addWidget(self.sigButton) buttonLayout1.addWidget(self.saveButton) buttonLayout1.addWidget(self.settingsButton) buttonLayout1.addStretch() buttonLayout2 = QHBoxLayout() buttonLayout2.addWidget(self.oldMassButton) buttonLayout2.addWidget(self.loadOldButton) buttonLayout2.addWidget(self.downloadButton) buttonLayout3 = QHBoxLayout() buttonLayout3.addWidget(self.newMassButton) buttonLayout3.addWidget(self.loadNewButton) buttonLayout3.addWidget(self.uploadButton) oldMapSummary = QVBoxLayout() oldMapSummary.addWidget(self.oldMapMass) oldMapSummary.addWidget(self.oldMapTime) oldMapSummary.addWidget(self.oldMapSigs) newMapSummary = QVBoxLayout() newMapSummary.addWidget(self.newMapMass) newMapSummary.addWidget(self.newMapTime) newMapSummary.addWidget(self.newMapSigs) mainLayout = QGridLayout() mainLayout.addWidget(self.oldMapping, 0, 0) mainLayout.addWidget(self.newMapping, 0, 1) mainLayout.addLayout(buttonLayout1, 0, 2) mainLayout.addLayout(oldMapSummary, 1, 0) mainLayout.addLayout(buttonLayout2, 2, 0) mainLayout.addLayout(newMapSummary, 1, 1) mainLayout.addLayout(buttonLayout3, 2, 1) self.setLayout(mainLayout)