def seller_decode(self, hexTx): hexTx = hexTx.strip().replace("\n", "").replace("\r", "").replace(" ", "") try: int(hexTx, 16) except ValueError: raise try: tx = self.rpc_call("decoderawtransaction", [hexTx]) except namerpc.RpcError as e: if (e.args[0]["error"]["code"] == -8 or e.args[0]["error"]["code"] == -22): # decode errors raise Exception("decode error") raise # analyze tx self.D = antpyshared.analyze_tx(tx, self.rpc_call, seller=True) nameList = self.rpc_call("name_list", [self.D["name"]]) if nameList == []: raise Exception("Name not in wallet: " + str(self.D["name"])) if nameList[0].has_key("transferred") and nameList[0]["transferred"]: raise Exception("Name has already been transferred: " + str(self.D["name"])) self.D["sellerAddress"] = nameList[0]["address"] self.D["hexTx"] = hexTx # only store after it has been checked self.D["vinOrig"] = tx["vin"] return self.D
def create_offer(self, name, bidNmc): # check name try: nameData = self.rpc_call("name_show", [name]) except namerpc.WalletError as e: if e.code == -4: # failed to read from db raise antpyshared.NameDoesNotExistError else: raise # inputs (select uses satoshis) bidSatoshis = antpyshared.to_satoshis(bidNmc) unspent = self.rpc_call("listunspent") for u in unspent: u["satoshis"] = antpyshared.to_satoshis(u["amount"]) inputs = antpyshared.select(unspent, bidSatoshis + antpyshared.TXFEESATOSHIS) # !!! check for too many inputs sumInputsNmc = sum([i["amount"] for i in inputs]) # outputs outputs = {nameData["address"] : bidNmc} # Bitcoin client will do proper rounding changeNmc = sumInputsNmc - bidNmc - antpyshared.TXFEENMC if antpyshared.to_satoshis(changeNmc) != 0: buyerChangeAddress = self.rpc_call("getnewaddress") outputs[buyerChangeAddress] = changeNmc # name_op buyerNameAddress = self.rpc_call("getnewaddress") nameOp = {"op" : "name_update", "name" : name, "value" : "", # name data !!! make changeable by user "address" : buyerNameAddress} inputs.append(nameData) # assembly if debug: print "inputs--------------------" pprint.pprint(inputs) print "outputs-------------------" pprint.pprint(outputs) print "nameop--------------------" pprint.pprint(nameOp) rawTx = self.rpc_call("createrawtransaction", [inputs, outputs, nameOp]) # fee check (not easily possible - buyer/seller need to verify their output values) if debug: tx = self.rpc_call("decoderawtransaction", [rawTx]) print "tx------------------------" pprint.pprint(tx) # buyer sign r = self.rpc_call("signrawtransaction", [rawTx]) rawTx = r["hex"] # buyer check tx = self.rpc_call("decoderawtransaction", [rawTx]) D = antpyshared.analyze_tx(tx, self.rpc_call, seller=False) D["rawTx"] = rawTx # only store after it has been checked assert name == D["name"] if debug: print D return D