Skip to content

Instantly share code, notes, and snippets.

View kumrzz's full-sized avatar

Kumar Ghosh kumrzz

View GitHub Profile
@kumrzz
kumrzz / leetcode-925-long-pressed-name.py
Created August 8, 2023 13:43
leetcode-925-long-pressed-name , mostly off goodtecher.com
class Solution:
def isLongPressedName(self, name: str, typed: str) -> bool:
print(name,typed)
groups_name = []
groups_name_count = []
prev = None
for c in name:
if c != prev:
groups_name.append(c)
prev = c
@kumrzz
kumrzz / testnetvariouspushtxmethods.py
Created January 2, 2017 19:37
various(4) BTC testnet transmit / propagate methods, all failed
"""
various(4) BTC testnet transmit / pushtx/ propagate methods, all failed :(
---------------------------------------
sending using helloblock:
HTTPSConnectionPool(host='testnet.helloblock.io', port=443): Max retries exceeded with url: /v1/transactions (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x000000000475E860>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed',))
---------------------------------------
sending using blockcypher:
{'error': "Couldn't deserialize request: invalid character 'x' in literal true (expecting 'r')"}
---------------------------------------
sending using blockcypher @ sessions:
"""
assumes you've entered (sendamount+fee) greater than Wallet balance
ignores special treatment of vout for coinbase tx
ignores fee considerations, assumes this is already part of nTargetValue
https://github.com/bitcoin/bitcoin/blob/v0.5.3/src/wallet.cpp#L760
http://bitcoin.stackexchange.com/questions/1077/what-is-the-coin-selection-algorithm
"""
import random
def SelectCoins():
@kumrzz
kumrzz / multimultisigspendtest.py
Created September 8, 2016 18:44
sending from 2x p2sh addresses in one(single) push to the bitcoin testnet
"""
OUTPUT:
private key#2:
9950aad11fc33c2d4a1f206e043c9755b377cf0bd7d6c93713143a3d23b0671d
public key#1:
0320869668e199a9499a41636983dfe337ca4878ee4170fcccd599b5674a02d055
p2sh wallet:
2NAFVo3PXKoND1JvLkGug3FFmyzs9TxEy8X
...
@kumrzz
kumrzz / seed2keys.py
Last active May 16, 2017 14:23 — forked from romanz/seed2keys.py
Creates public and private keys from Electrum 2.0 seed
#!/usr/bin/env python
''' Run from "electrum/lib" directory.
ThomaxV started a discussion on https://bitcointalk.org/index.php?topic=274182.msg2939599#msg2939599
about changing the HD derivation logic in electrum 2. The below post:
http://bitcoin.stackexchange.com/questions/37013/how-to-import-a-hd-wallet-from-an-extended-private-key
confirms that the format is actually m/c/i (and not m/44'/0'/a'/c/i)
so I have altered https://gist.github.com/romanz/4b32782bfc0ff4984713 accordingly:
tested to work with keys/addresses exported from electrum 2.7.0
note Electrum has a "gap limit" of 20, so loop @ level "c" to get the next 20 addresses
'''
from blockcypher import create_unsigned_tx
dest_addr = "mgMZ3UdQsEmJ1ebjRV9ibTn1DFCxgmMo7a"
priv1 = "9c46389dde9e820294b68defd44e01da12cfe1374324cf27c198e4822e7d9d1e"
pub1 = "0471b0e83960b9a8ad980400fc7ee85e9739009f0ee08ef033784bdcefe7f38c64e9ba2b9d842089486735556e0b1940304db510ad521865bb5b028dee229c1dbd"
addr1 = "mySFV5esqFZqz8maEVjEodxwc9xyhXMmmY"
pub2 = '04a3cc3225df2ef6ca72e960c5cab0059731301d5efe61e7ffa1c4cac3a8e4994adcb27f01a282b7747d96ffdad324e774087c4a35197e99016bca62541af26eab'
addr2 = 'mouKAz9iAgMJzZjiiw4bZ4rxkJapkTXVDZ'