Exemple #1
0
def get_xpub_unspent_addrs(*args):
    """Takes bip32 xpub (or xprv) and returns addresses with balance"""
    from bitcoin.main import multiaccess, pubtoaddr
    from bitcoin.deterministic import bip32_descend, bip32_ckd, bip32_privtopub
    xpubs = [bip32_privtopub(x) if x.startswith("xprv") else x for x in args]
    data = {"addr": " ".join(xpubs)}
    jdata = json.loads(
        make_request("https://www.blockonomics.co/api/balance",
                     json.dumps(data)))
    jdata = jdata.get("response")
    addrs, values = multiaccess(jdata, "addr"), multiaccess(jdata, "confirmed")
    d = dict.fromkeys(xpubs, {})
    for xpub in xpubs:
        c, i = 0, 0
        while c <= 1:
            addr = pubtoaddr(bip32_descend(bip32_ckd(xpub, c), i))
            if addr in addrs:
                d[xpub].update({
                    "m/%d/%d" % (c, i):
                    "%s:%d" % (addr, values[addrs.index(addr)])
                })
            else:
                c += 1
            i += 1
    return d.values()[0] if len(d) == 1 else d
Exemple #2
0
def get_xpub_outputs(*args):
    from bitcoin.main import multiaccess
    xpubs = [bip32_privtopub(x) if x.startswith("xprv") else x for x in args]
    jdata = json.loads(make_request("https://www.blockonomics.co/api/balance", \
                                      json.dumps({"addr": " ".join(xpubs)}))).get("response")
    addrs = multiaccess(jdata, 'addr')
    values = map(str, multiaccess(jdata, "confirmed" or "unconfirmed"))
    return [":".join(y) for y in [x for x in zip(addrs, values)]]
Exemple #3
0
def get_xpub_addrs(*args):
    """Returns all known (used) addresses for xpub(s)"""
    from bitcoin.main import multiaccess
    xpubs = [bip32_privtopub(x) if x.startswith("xprv") else x for x in args]
    jdata = json.loads(make_request("https://www.blockonomics.co/api/balance", \
                                      json.dumps({"addr": " ".join(xpubs)}))).get("response")
    addrs = multiaccess(jdata, "addr")
    return addrs
Exemple #4
0
def get_xpub_outputs(*args):
    from bitcoin.main import multiaccess
    xpubs = [bip32_privtopub(x) if x.startswith("xprv") else x for x in args]
    jdata = json.loads(make_request("https://www.blockonomics.co/api/balance", \
                                      json.dumps({"addr": " ".join(xpubs)}))).get("response")
    addrs = multiaccess(jdata, 'addr')
    values = map(str, multiaccess(jdata, "confirmed" or "unconfirmed"))
    return [":".join(y) for y in [x for x in zip(addrs, values)]]
Exemple #5
0
def get_xpub_addrs(*args):
    """Returns all known (used) addresses for xpub(s)"""
    from bitcoin.main import multiaccess
    xpubs = [bip32_privtopub(x) if x.startswith("xprv") else x for x in args]
    jdata = json.loads(make_request("https://www.blockonomics.co/api/balance", \
                                      json.dumps({"addr": " ".join(xpubs)}))).get("response")
    addrs = multiaccess(jdata, "addr")
    return addrs
Exemple #6
0
def get_xpub_unspent_addrs(*args):
    """Takes bip32 xpub (or xprv) and returns addresses with balance"""
    from bitcoin.main import multiaccess, pubtoaddr
    from bitcoin.deterministic import bip32_descend, bip32_ckd, bip32_privtopub
    xpubs = [bip32_privtopub(x) if x.startswith("xprv") else x for x in args]
    data = {"addr": " ".join(xpubs)}
    jdata = json.loads(make_request("https://www.blockonomics.co/api/balance", json.dumps(data)))
    jdata = jdata.get("response")
    addrs, values = multiaccess(jdata,"addr"), multiaccess(jdata,"confirmed")
    d = dict.fromkeys(xpubs, {})
    for xpub in xpubs:
        c, i = 0, 0
        while c <= 1:
            addr = pubtoaddr(bip32_descend(bip32_ckd(xpub, c), i))
            if addr in addrs:
                d[xpub].update({
                                "m/%d/%d" % (c, i): "%s:%d" % (addr, values[addrs.index(addr)])
                                })
            else:
                c += 1
            i += 1
    return d.values()[0] if len(d) ==1 else d
Exemple #7
0
# 파이썬 실습 파일: 3-9.HDWallet.py
# pybitcointools (https://github.com/vbuterin/pybitcointools)
# pybitcointools를 설치하지 않고 배포용 실습 코드의 bitcoin 폴더가 있는 곳에서 실행한다.
import bitcoin.main as btc
import bitcoin.deterministic as det

# seed 값인 단어 목록 (Mnemonic words)를 임의로 설정하고
# Master private key와 master public key를 생성한다.
seed = b'ksLee hlpark shcho previous andante apple solee clk learn'
mPrv = det.bip32_master_key(seed)  # master private key
mPub = det.bip32_privtopub(mPrv)   # master public key

# 계층-1의 extended private key와 public key를 생성한다.
# Depth-1 (m=0, m/1)
xPrv01 = det.bip32_ckd(mPrv, 1)     # 마스터 개인키로 Depth-1의 개인키를 생성한다
xPub01 = det.bip32_ckd(mPub, 1)     # 마스터 공개키로 Depth-1의 공개키를 생성한다

# 계층-2의 extended private key와 public key를 생성한다.
# Depth-2 (m/1/0)
xPrv010 = det.bip32_ckd(xPrv01, 0)  # Depth-1의 개인키로 Depth-2의 개인키를 생성한다
xPub010 = det.bip32_ckd(xPub01, 0)  # Depth-1의 공개키로 Depth-2의 공개키를 생성한다

# 계층-3의 extended private key와 public key를 생성한다.
# Depth-3 (m/1/0/0)
xPrv0100 = det.bip32_ckd(xPrv010, 0) # Depth-2의 개인키로 Depth-3의 개인키를 생성한다
xPub0100 = det.bip32_ckd(xPub010, 0) # Depth-2의 공개키로 Depth-3의 공개키를 생성한다

# Address (m/1/0/0)
prv0100 = det.bip32_extract_key(xPrv0100)
pub0100 = det.bip32_extract_key(xPub0100)
adr0100 = btc.pubkey_to_address(pub0100, 0x00) # Depth-3의 공개키로 주소를 생성한다