ltc address converted into scripthash library?
Closed this issue · 2 comments
Jamiejoin commented
I need to convert the address to scripthash to use electrumx. Is there a library or method for this?Or do I have examples for reference? thank you very much
kyuupichan commented
It's explained in the documentation under "Script Hashes".
Jamiejoin commented
I tried to use the following method to convert the address into scripthash, but the balance of my address could not be checked in electrumx.
@classmethod
def hashX_from_script(cls, script):
'''Returns a hashX from a script.'''
return sha256(script).digest()
@classmethod
def address_to_hashX(cls, address):
'''Return a hashX given a coin address.'''
return cls.hashX_from_script(cls.pay_to_address_script(address))
# coding:utf-8
import electrumx.lib.coins as coins
coins.Litecoin.address_to_hashX("LiL6rJxoVKjaPWHCJXnhYjRpvyqigkENDh").hex()
Get scripthash
(venv) MacBook-Pro:electrumx-master liyun$ python3 test.py
d3de2e547a1a23600722a8e8e2bdb656f5825cff007c0fdbc8e39916e1c02287
Get balance
def get_balance(self, hashaddr):
#hashaddr = address_to_scripthash(addr)
self.method = "blockchain.scripthash.get_balance"
self.params = hashaddr
self.flag = False
while True:
try:
rep = self.loop.run_until_complete(self.electrumx())
break
except socket.error as e:
print("electrumx socket error,do reconnect, %s", e)
sleep(1)
except Exception as e:
print("electrumx other error occur, error is %s", e)
sleep(1)
return rep['result']['confirmed'],rep['result']['unconfirmed']
self.get_balance("d3de2e547a1a23600722a8e8e2bdb656f5825cff007c0fdbc8e39916e1c02287")
Please forgive my method may be wrong, but I don’t know where I did it wrong, I hope to get help, thank you very much