def issue_coins(self, moniker, pck, units, atoms_in_unit): """Issues a new color of name <moniker> using coloring scheme <pck> with <units> per share and <atoms_in_unit> total. """ color_definition_cls = ColorDefinition.get_color_def_cls_for_code(pck) if not color_definition_cls: msg = 'Color scheme "%s" not recognized' raise InvalidColorDefinitionError(msg % pck) total = int(units * atoms_in_unit) op_tx_spec = SimpleOperationalTxSpec(self.model, None) wam = self.model.get_address_manager() address = wam.get_new_genesis_address() colorvalue = SimpleColorValue(colordef=GENESIS_OUTPUT_MARKER, value=total) color_target = ColorTarget(address.get_address(), colorvalue) op_tx_spec.add_target(color_target) genesis_ctxs = color_definition_cls.compose_genesis_tx_spec(op_tx_spec) genesis_tx = self.model.transform_tx_spec(genesis_ctxs, 'signed') height = self.model.ccc.blockchain_state.get_block_count() - 1 genesis_tx_hash = self.publish_tx(genesis_tx) color_desc = ':'.join([pck, genesis_tx_hash, '0', str(height)]) adm = self.model.get_asset_definition_manager() asset = adm.add_asset_definition({"monikers": [moniker], "color_set": [color_desc], "unit": atoms_in_unit}) wam.update_genesis_address(address, asset.get_color_set()) # scan the tx so that the rest of the system knows self.model.ccc.colordata.cdbuilder_manager.scan_txhash( asset.color_set.color_id_set, genesis_tx_hash)
def issue_coins(self, moniker, pck, units, atoms_in_unit): """Issues a new color of name <moniker> using coloring scheme <pck> with <units> per share and <atoms_in_unit> total. """ color_definition_cls = ColorDefinition.get_color_def_cls_for_code(pck) if not color_definition_cls: raise InvalidColorDefinitionError( 'color scheme %s not recognized' % pck) total = units * atoms_in_unit op_tx_spec = SimpleOperationalTxSpec(self.model, None) wam = self.model.get_address_manager() address = wam.get_new_genesis_address() colorvalue = SimpleColorValue(colordef=GENESIS_OUTPUT_MARKER, value=total) color_target = ColorTarget(address.get_address(), colorvalue) op_tx_spec.add_target(color_target) genesis_ctxs = color_definition_cls.compose_genesis_tx_spec(op_tx_spec) genesis_tx = self.model.transform_tx_spec(genesis_ctxs, 'signed') height = self.model.ccc.blockchain_state.bitcoind.getblockcount() \ - 1 genesis_tx_hash = self.publish_tx(genesis_tx) color_desc = ':'.join([pck, genesis_tx_hash, '0', str(height)]) adm = self.model.get_asset_definition_manager() asset = adm.add_asset_definition({ "monikers": [moniker], "color_set": [color_desc], "unit": atoms_in_unit }) wam.update_genesis_address(address, asset.get_color_set()) # scan the tx so that the rest of the system knows self.model.ccc.colordata.cdbuilder_manager.scan_txhash( asset.color_set.color_id_set, genesis_tx_hash)
def add_coins(self): self.config['asset_definitions'] = [ {"color_set": [""], "monikers": ["bitcoin"], "unit": 100000000}, {"color_set": [self.cspec], "monikers": ['test'], "unit": 1},] self.config['hdwam'] = { "genesis_color_sets": [ [self.cspec], ], "color_set_states": [ {"color_set": [""], "max_index": 1}, {"color_set": [self.cspec], "max_index": 7}, ] } self.config['bip0032'] = True self.pwallet = PersistentWallet(self.path, self.config) self.pwallet.init_model() self.model = self.pwallet.get_model() self.ewc.model = self.model self.wc.model = self.model def null(a): pass self.wc.publish_tx = null # modify model colored coin context, so test runs faster ccc = self.model.ccc cdbuilder = ColorDataBuilderManager( ccc.colormap, ccc.blockchain_state, ccc.cdstore, ccc.metastore, AidedColorDataBuilder) ccc.colordata = ThinColorData( cdbuilder, ccc.blockchain_state, ccc.cdstore, ccc.colormap) # need to query the blockchain self.model.utxo_man.update_all() adm = self.model.get_asset_definition_manager() asset = adm.get_asset_by_moniker('test') cq = self.model.make_coin_query({"asset": asset}) utxo_list = cq.get_result() self.cd = ColorDefinition.from_color_desc(1, self.cspec) self.cv0 = SimpleColorValue(colordef=UNCOLORED_MARKER, value=100) self.cv1 = SimpleColorValue(colordef=self.cd, value=200) self.offer0 = MyEOffer(None, self.cv0, self.cv1) self.offer1 = MyEOffer(None, self.cv1, self.cv0)
def POST(self): blockchainstate = BlockchainState.from_url(None, testnet) # data is sent in as json data = json.loads(web.data()) self.require(data, 'txhash', "Prefetch requires txhash") self.require(data, 'output_set', "Prefetch requires output_set") self.require(data, 'color_desc', "Prefetch requires color_desc") txhash = data.get('txhash') output_set = data.get('output_set') color_desc = data.get('color_desc') limit = data.get('limit') # note the id doesn't actually matter we need to add it so # we have a valid color definition color_def = ColorDefinition.from_color_desc(9999, color_desc) # gather all the transactions and return them tx_lookup = {} def process(current_txhash, current_outindex): """For any tx out, process the colorvalues of the affecting inputs first and then scan that tx. """ if limit and len(tx_lookup) > limit: return if tx_lookup.get(current_txhash): return current_tx = blockchainstate.get_tx(current_txhash) if not current_tx: return tx_lookup[current_txhash] = blockchainstate.get_raw(current_txhash) # note a genesis tx will simply have 0 affecting inputs inputs = set() inputs = inputs.union( color_def.get_affecting_inputs(current_tx, [current_outindex])) for i in inputs: process(i.prevout.hash, i.prevout.n) for oi in output_set: process(txhash, oi) return tx_lookup
def POST(self): # data is sent in as json data = json.loads(web.data()) self.require(data, 'txhash', "Prefetch requires txhash") self.require(data, 'output_set', "Prefetch requires output_set") self.require(data, 'color_desc', "Prefetch requires color_desc") txhash = data.get('txhash') output_set = data.get('output_set') color_desc = data.get('color_desc') limit = data.get('limit') # note the id doesn't actually matter we need to add it so # we have a valid color definition color_def = ColorDefinition.from_color_desc(9999, color_desc) # gather all the transactions and return them tx_lookup = {} def process(current_txhash, current_outindex): """For any tx out, process the colorvalues of the affecting inputs first and then scan that tx. """ if limit and len(tx_lookup) > limit: return if tx_lookup.get(current_txhash): return current_tx = blockchainstate.get_tx(current_txhash) if not current_tx: return tx_lookup[current_txhash] = blockchainstate.get_raw(current_txhash) # note a genesis tx will simply have 0 affecting inputs inputs = set() inputs = inputs.union( color_def.get_affecting_inputs(current_tx, [current_outindex])) for i in inputs: process(i.prevout.hash, i.prevout.n) for oi in output_set: process(txhash, oi) return tx_lookup
def prefetch(self, txhash, output_set, color_desc, limit): # note the id doesn't actually matter we need to add it so # we have a valid color definition color_def = ColorDefinition.from_color_desc(9999, color_desc) # gather all the transactions and return them tx_lookup = {} @defer.inlineCallbacks def process(current_txhash, current_outindex): """For any tx out, process the colorvalues of the affecting inputs first and then scan that tx. """ if limit and len(tx_lookup) > limit: defer.returnValue(None) if tx_lookup.get(current_txhash): defer.returnValue(None) raw_transaction = yield self.bitcoind.call('getrawtransaction', [current_txhash]) txbin = bitcoin.core.x(txhex) tx = bitcoin.core.CTransaction.deserialize(txbin) current_tx = AsyncCTransaction.from_bitcoincore(txhash, tx, self) if not current_tx: defer.returnValue(None) tx_lookup[current_txhash] = raw_transaction # note a genesis tx will simply have 0 affecting inputs inputs = set() inputs = inputs.union( color_def.get_affecting_inputs(current_tx, [current_outindex])) for i in inputs: yield process(i.prevout.hash, i.prevout.n) for oi in output_set: yield process(txhash, oi) defer.returnValue(tx_lookup)
def POST(self): # data is sent in as json data = json.loads(web.input().keys()[0]) self.require(data, 'txhash', "Prefetch requires txhash") self.require(data, 'output_set', "Prefetch requires output_set") self.require(data, 'color_desc', "Prefetch requires color_desc") txhash = data.get('txhash') output_set = data.get('output_set') color_desc = data.get('color_desc') limit = data.get('limit') color_def = ColorDefinition.from_color_desc(17, color_desc) tx_lookup = {} def process(current_txhash, current_outindex): """For any tx out, process the colorvalues of the affecting inputs first and then scan that tx. """ if limit and len(tx_lookup) > limit: return if tx_lookup.get(current_txhash): return current_tx = blockchainstate.get_tx(current_txhash) if not current_tx: return tx_lookup[current_txhash] = blockchainstate.get_raw(current_txhash) # note a genesis tx will simply have 0 affecting inputs inputs = set() inputs = inputs.union( color_def.get_affecting_inputs(current_tx, [current_outindex])) for i in inputs: process(i.prevout.hash, i.prevout.n) for oi in output_set: process(txhash, oi) return tx_lookup
def add_coins(self): self.config['asset_definitions'] = [ { "color_set": [""], "monikers": ["bitcoin"], "unit": 100000000 }, { "color_set": [self.cspec], "monikers": ['test'], "unit": 1 }, ] self.config['hdwam'] = { "genesis_color_sets": [ [self.cspec], ], "color_set_states": [ { "color_set": [""], "max_index": 1 }, { "color_set": [self.cspec], "max_index": 7 }, ] } self.config['bip0032'] = True self.pwallet = PersistentWallet(self.path, self.config) self.pwallet.init_model() self.model = self.pwallet.get_model() self.ewc.model = self.model self.wc.model = self.model def null(a): pass self.wc.publish_tx = null # modify model colored coin context, so test runs faster ccc = self.model.ccc cdbuilder = ColorDataBuilderManager(ccc.colormap, ccc.blockchain_state, ccc.cdstore, ccc.metastore, AidedColorDataBuilder) ccc.colordata = ThinColorData(cdbuilder, ccc.blockchain_state, ccc.cdstore, ccc.colormap) # need to query the blockchain self.model.utxo_man.update_all() adm = self.model.get_asset_definition_manager() asset = adm.get_asset_by_moniker('test') cq = self.model.make_coin_query({"asset": asset}) utxo_list = cq.get_result() self.cd = ColorDefinition.from_color_desc(1, self.cspec) self.cv0 = SimpleColorValue(colordef=UNCOLORED_MARKER, value=100) self.cv1 = SimpleColorValue(colordef=self.cd, value=200) self.offer0 = MyEOffer(None, self.cv0, self.cv1) self.offer1 = MyEOffer(None, self.cv1, self.cv0)