class GarlicoinWrapper:
    def __init__(self, rpcUrl, rpcUser, rpcPass):
        self.srv = Server(rpcUrl, auth=(rpcUser, rpcPass))

    def get_user_address(self, userId):
        addresses = self.srv.getaddressesbyaccount(str(userId))
        if not addresses:
            return self.generate_address(str(userId))
        else:
            return addresses[0]

    def generate_address(self, userId):
        return self.srv.getnewaddress(str(userId))

    def get_balance(self, userId):
        return self.srv.getbalance(str(userId))

    def transfer(self, userIdSrc, grlcDest, amount):
        return self.srv.sendfrom(str(userIdSrc), grlcDest, amount)

    def move_between_accounts(self, userIdSrc, userIdDest, amount):
        try:
            return self.srv.move(str(userIdSrc), str(userIdDest),
                                 round(amount, 8))
        except jsonrpc.TransportError as e:
            err = json.loads(e.server_response.content)['error']['message']
            msg = f"{ctx.author.mention} ERROR: {err}: {e.request.body['params']}"
            return msg
Example #2
0
from pprint import pprint
from jsonrpc_requests import Server
server = Server('http://localhost:37128')

server.getstatus()

server.createwallet("test1", "samkorn")

# Throws "Response without a result field"
server.selectwallet("test1")

server.getwalletinfo("test1")

server.listunspentcoins()

server.getnewaddress("test receive")

server.send()
{
    "payments": [{
        "sendto": "tb1qgvnht40a08gumw32kp05hs8mny954hp2snhxcz",
        "amount": 15000,
        "label": "David"
    }, {
        "sendto": "tb1qpyhfrpys6skr2mmnc35p3dp7zlv9ew4k0gn7qm",
        "amount": 86200,
        "label": "Michael"
    }],
    "coins": [{
        "transactionid":
        "ab83d9d0b2a9873b8ab0dc48b618098f3e7fbd807e27a10f789e9bc330ca89f7",
Example #3
0
from jsonrpc_requests import Server
bitcoind = Server('http://chains.bo:8332', auth=('btcrpc', 'btc'))

address = bitcoind.getnewaddress()
privkey = bitcoind.dumpprivkey(address)

print(address)
print(privkey)