{"action":"closed","issue":{"url":"https://api.github.com/repos/richardkiss/pycoin/issues/87","labels_url":"https://api.github.com/repos/richardkiss/pycoin/issues/87/labels{/name}","comments_url":"https://api.github.com/repos/richardkiss/pycoin/issues/87/comments","events_url":"https://api.github.com/repos/richardkiss/pycoin/issues/87/events","html_url":"https://github.com/richardkiss/pycoin/issues/87","id":58758848,"number":87,"title":"Bitcoin Testnet Encoding","user":{"login":"shayanb","id":309108,"avatar_url":"https://avatars.githubusercontent.com/u/309108?v=3","gravatar_id":"","url":"https://api.github.com/users/shayanb","html_url":"https://github.com/shayanb","followers_url":"https://api.github.com/users/shayanb/followers","following_url":"https://api.github.com/users/shayanb/following{/other_user}","gists_url":"https://api.github.com/users/shayanb/gists{/gist_id}","starred_url":"https://api.github.com/users/shayanb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shayanb/subscriptions","organizations_url":"https://api.github.com/users/shayanb/orgs","repos_url":"https://api.github.com/users/shayanb/repos","events_url":"https://api.github.com/users/shayanb/events{/privacy}","received_events_url":"https://api.github.com/users/shayanb/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-02-24T15:58:42Z","updated_at":"2015-11-20T00:32:14Z","closed_at":"2015-11-20T00:32:14Z","body":"I've been working to make pycoin work with Bitcoin Testnet Multisig, I added Blockr.io testnet API to get the spendables, but the chain of code getting there has not yet been fixed.\r\n\r\nThis is the code I used to get the testnet spendables:\r\n```\r\ndef spendables_for_addr(address, netcode='BTC'):\r\n    \"\"\"\r\n    Return a list of Spendable objects for the\r\n    given bitcoin address.\r\n    \"\"\"\r\n    from pycoin.convention import btc_to_satoshi\r\n    from pycoin.tx import Tx, Spendable\r\n    from urllib2 import urlopen\r\n\r\n    #Support for bitcoin testnet api in Blockr.io\r\n    if netcode == \"XTN\":\r\n        URL = \"http://tbtc.blockr.io/api/v1/address/unspent/%s\" % address\r\n    if netcode == \"BTC\":\r\n        URL = \"http://btc.blockr.io/api/v1/address/unspent/%s\" % address\r\n    r = json.loads(urlopen(URL).read().decode(\"utf8\"))\r\n    spendables = []\r\n    for u in r.get(\"data\", {}).get(\"unspent\", []):\r\n        coin_value = btc_to_satoshi(u.get(\"amount\"))\r\n        script = h2b(u.get(\"script\"))\r\n        previous_hash = h2b_rev(u.get(\"tx\"))\r\n        previous_index = u.get(\"n\")\r\n        spendables.append(Spendable(coin_value, script, previous_hash, previous_index))\r\n    return spendables\r\n```\r\n\r\nNow the problem is with the WIF encoding, I guess the solution would be to pass netcode all along the functions to reach https://github.com/richardkiss/pycoin/blob/master/pycoin/encoding.py#L187 or probably to LazySecretExponentDB(...)\r\n\r\nHere is the encoding error:\r\n```\r\n    tx_final =  tx_utils.create_signed_tx([spendables_for_addr(address, netcode=temp_netcode)[0]], [testnet_address], wifs=([key.wif() for key in keys[:M]]), fee=1000, netcode=temp_netcode, p2sh_lookup=p2sh_lookup)\r\n  File \"../pycoin/pycoin/tx/tx_utils.py\", line 202, in create_signed_tx\r\n    sign_tx(tx, wifs=wifs, secret_exponent_db=secret_exponent_db, **kwargs)\r\n  File \"../pycoin/pycoin/tx/tx_utils.py\", line 170, in sign_tx\r\n    tx.sign(LazySecretExponentDB(wifs, secret_exponent_db), **kwargs)\r\n  File \"../pycoin/pycoin/tx/Tx.py\", line 374, in sign\r\n    hash160_lookup, idx, self.unspents[idx].script, hash_type=hash_type, **kwargs)\r\n  File \"../pycoin/pycoin/tx/Tx.py\", line 249, in sign_tx_in\r\n    existing_script=self.txs_in[tx_in_idx].script, **kwargs)\r\n  File \"../pycoin/pycoin/tx/pay_to/ScriptPayToScript.py\", line 41, in solve\r\n    underlying_solution = script_obj.solve(**kwargs)\r\n  File \"../pycoin/pycoin/tx/pay_to/ScriptMultisig.py\", line 118, in solve\r\n    result = db.get(hash160)\r\n  File \"../pycoin/pycoin/tx/tx_utils.py\", line 29, in get\r\n    secret_exponent = wif_to_secret_exponent(wif)\r\n  File \"../pycoin/pycoin/encoding.py\", line 203, in wif_to_secret_exponent\r\n    return wif_to_tuple_of_secret_exponent_compressed(wif, allowable_wif_prefixes=allowable_wif_prefixes, netcode = netcode)[0]\r\n  File \"../pycoin/pycoin/encoding.py\", line 197, in wif_to_tuple_of_secret_exponent_compressed\r\n    raise EncodingError(\"unexpected first byte of WIF %s\" % wif)\r\npycoin.encoding.EncodingError: unexpected first byte of WIF cVVNL17sdMoGQasdSdj4jGJHTaz6JohgmS2AahhhatQwRFn\r\n```\r\n\r\nThe workaround for now is to comment these two lines https://github.com/richardkiss/pycoin/blob/master/pycoin/encoding.py#L195-L196:\r\n\r\n```\r\n    if actual_prefix not in allowable_wif_prefixes:\r\n        raise EncodingError(\"unexpected first byte of WIF %s\" % wif)\r\n```\r\nor add **[b'\\xef']** to allowable_wif_prefixes."}}