Skip to content

Stage 1: Connect wallet to bitmarkd RPC #1

@melvincarvalho

Description

@melvincarvalho

Overview

Replace the ElectrumX network layer with direct bitmarkd RPC calls to enable the wallet to:

  • Query address balances
  • Fetch transaction history
  • Broadcast signed transactions

This is a temporary backend for Stage 1 PoC. Stage 2 will migrate to proper ElectrumX protocol.

Architecture

Current (broken):
┌─────────────┐      ┌─────────────┐
│  Electrum   │ ───? │  ElectrumX  │  (no server exists)
│  Wallet     │      │  Server     │
└─────────────┘      └─────────────┘

Stage 1 Target:
┌─────────────┐      ┌─────────────┐
│  Electrum   │ RPC  │  bitmarkd   │
│  Wallet     │ ───► │  (local)    │
└─────────────┘      └─────────────┘

bitmarkd RPC Methods Required

Wallet Function bitmarkd RPC Call
Get balance getreceivedbyaddress or listunspent
Get UTXOs listunspent
Get tx history listtransactions / gettransaction
Broadcast tx sendrawtransaction
Get fee estimate estimatefee
Verify address validateaddress
Get block height getblockcount

Implementation Plan

1. Create RPC Client Module

New file: electrum/bitmarkd_rpc.py

class BitmarkdRPC:
    def __init__(self, host='127.0.0.1', port=9266, user=None, password=None):
        self.url = f'http://{host}:{port}'
        self.auth = (user, password) if user else None
    
    async def call(self, method, *params):
        """Make RPC call to bitmarkd"""
        pass
    
    async def get_balance(self, address):
        """Get confirmed balance for address"""
        pass
    
    async def list_unspent(self, addresses):
        """Get UTXOs for addresses"""
        pass
    
    async def broadcast_transaction(self, raw_tx):
        """Broadcast signed transaction"""
        pass

2. Create Network Adapter

New file: electrum/network_rpc.py

Implement the same interface as network.py but using bitmarkd RPC:

class BitmarkdNetwork:
    """Drop-in replacement for Network class using bitmarkd RPC"""
    
    async def get_address_history(self, address):
        pass
    
    async def get_address_balance(self, address):
        pass
    
    async def broadcast_transaction(self, tx):
        pass

3. Modify Wallet Initialization

In electrum/daemon.py or startup code:

  • Add config option: --rpc-host, --rpc-port, --rpc-user, --rpc-password
  • Or read from ~/.bitmark/bitmark.conf

4. Configuration

Read bitmarkd credentials from ~/.bitmark/bitmark.conf:

rpcuser=bitmarkrpc
rpcpassword=yourpassword
rpcport=9266

Or allow command-line override:

./run_electrum gui --rpc-host=127.0.0.1 --rpc-port=9266

Files to Modify

File Changes
electrum/bitmarkd_rpc.py NEW - RPC client
electrum/network_rpc.py NEW - Network adapter
electrum/daemon.py Add RPC config options
electrum/network.py May need interface changes
electrum/synchronizer.py May need to use new adapter

Testing

  1. Unit tests for RPC client
  2. Integration test with running bitmarkd:
    # Start bitmarkd
    bitmarkd -daemon
    
    # Test wallet
    ./run_electrum getbalance -w test_wallet

Limitations (Stage 1)

  • Requires local bitmarkd node (not lightweight)
  • No SPV verification (trusts the node)
  • Single server (no redundancy)

These limitations are addressed in Stage 2 with ElectrumX.

References

Acceptance Criteria

  • Wallet can connect to local bitmarkd
  • Balance displays correctly for addresses with funds
  • Transaction history shows past transactions
  • Can send BTM to another address
  • Error handling for RPC connection failures

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions