[spam][crazy][wrong][ot] ramblings
Karl
gmkarl at gmail.com
Wed Nov 24 16:59:36 PST 2021
1747
omigoodness! the thing i thought was 'in an hour' is not actually
happening this week. instead i have a trip to prepare for.
for now, i'll work a little more. i generated a private key for
testing! i'll send it funs!
i use mainnet for testing [so that i burn funds in doing so. helps my
psychological issues to waste money. the ones where i think i'm being
beaten up by a group that hates me. they do less imaginary beating up
if i waste my money.]
1747
i sent $0.99 in BSV to my test address ! 1749.
here's the private key line for gits and shiggles:
# note: this private key is not private
privkey = bitcoinx.PrivateKey.from_hex('088412ca112561ff5db3db83e2756fe447d36ba3c556e158c8f016a2934f7279')
1750 now for testingish ummmmmmmmmmmmmmmmmmmmm
uhhhhhhhhhhhhh
i'll want to enumerate that utxo from the address. so i can prep for
buliding transactions. 1751
1756 the rpc server doesn't like my scripthash =/ i have its source
code! i'll see what's wrong with it!
RPCError: (1, '423410ca994a0641076449 is not a valid script hash')
1757 ooookay hashX and scripthash are actually different formats.
1803 hashx's are truncated to 11 bytes. scripthashes are 32 hexadecimal bytes.
1808 woohoo! i got a utxo! a scripthash is the hexadecimal
byte-reversed sha256 hash of a script output's raw bytes. there's one
per address, kinda.
y'know ... that means a lot of other things. anything that's a
repeated script output, you could ask an electrum server to list them.
.... maybe? dunno, maybe not. it's 1810.
here's my utxo:
[{'tx_hash': '86ca468461094f502eb21b3161366e626056f0d299d99080539cfcb4e02a8dc3',
'tx_pos': 0,
'height': 714954,
'value': 647200}]
i guess i'll want my api function to convert that to a structure from
a library. luckily it includes value, which is super useful for
transaction building.
bitcoinx doesn't have a good structure =/ i guess i'll just return the dict.
1815 i don't remember about hte 'script_sig' field in transaction
inputs. i think that's where we complete he script of the preceding
output, with a cryptographic signature? i wonder how ot generate it.
1816. maybe the bitcoinx tests will show how to do this.
1845 i've signed a dummy input in a repl using the electrum (not
electrumx) libraries.
pre_hash = sha256d(bfh(self.serialize_preimage(txin_index,
bip143_shared_txdigest_fields=bip143_shared_txdigest_fields)))
privkey = ecc.ECPrivkey(privkey_bytes)
sig = privkey.sign_transaction(pre_hash)
sig = bh2u(sig) + sighash_type
looks like it serializes something, then double-sha256's the bytes,
then performs an EC signature on that hash ... then passes that to
bh2u and appends sighash_type (a basic byte)
self.add_signature_to_txin(txin_idx=i,
signing_pubkey=pubkey, sig=sig)
so 3 funcs to sort out
elif txin.script_type in ['p2pkh', 'p2wpkh', 'p2wpkh-p2sh']:
pubkey = pubkeys[0]
pkh = bh2u(hash_160(bfh(pubkey)))
return bitcoin.pubkeyhash_to_p2pkh_script(pkh)
gets p2pkh script
def pubkeyhash_to_p2pkh_script(pubkey_hash160: str) -> str:
return construct_script([
opcodes.OP_DUP,
opcodes.OP_HASH160,
pubkey_hash160,
opcodes.OP_EQUALVERIFY,
opcodes.OP_CHECKSIG
])
in electrumx, there's electrumx.lib.script.ScriptPubKey.P2PKH_script:
@classmethod
def P2PKH_script(cls, hash160):
return (bytes((OpCodes.OP_DUP, OpCodes.OP_HASH160))
+ Script.push_data(hash160)
+ bytes((OpCodes.OP_EQUALVERIFY, OpCodes.OP_CHECKSIG)))
this appears to be the electrum-non-x scriptsig for p2pkh:
elif _type == 'p2pkh':
return construct_script([sig_list[0], pubkeys[0]])
i'll try to do it by hand. 1901. hmm.
1907 this makes a p2pkh script in bitcoinx:
privkey.public_key.P2PKH_script().to_bytes()
1920 in bitcoinx, privkey.sign(data, bitcoinx.double_sha256)
1926 i've drafted code to sign an op_return transaction using only the
bitcoinx library
1940 1926 might have been a typo for 1936 or such. i'm noticing that
bitcoinx is bsv-specific. might be a better library out there.
dunno.
1951 transaction was rejected by network rules ! which is much farther.
1953 i believe i had set the transaction version to 0 instead of 1. uncertain.
1954 version fixed. now: 'missing inputs'.
i vaguely recall that 'missing inputs' might mean that the node i'm
sending the transaction to, hasn't received the utxo i'm spending.
1958 didn't byte-reverse the txid in the input !
1958 next network rule: mempool min fee not met. i wonder what my fee
was calculated to be. is there a way to query for this min fee?
i have accomplished much. sending this spamlog.
More information about the cypherpunks
mailing list