如何在没有网络连接的情况下从Bitcoinj钱包获取currentReceiveAddress?

时间:2017-12-17 16:46:33

标签: java bitcoin wallet bitcoinj

我们正在使用bitcoinj来处理比特币钱包。 Protobuf序列化Wallet主体作为字节数组存储在数据库中。

就我而言,没有必要连接到比特币网络来获取receive address,因为它是以某种方式从密钥计算的,存储在Wallet实体中。< / p>

所以我的问题 - 是否可以在不进行任何网络活动的情况下将protobuf反序列化为bitcoinj Wallet实体?

1 个答案:

答案 0 :(得分:0)

fun getBitcoinAddress() {
    val seedCode = "yard impulse luxury drive today throw farm pepper survey wreck glass federal"
    val wallet = Wallet.fromSeed(
        NetworkParameters.fromID(NetworkParameters.ID_MAINNET),
        DeterministicSeed(seedCode, null, "", 0L)
    )
    val changeAddress = wallet.currentChangeAddress()
    val freshAddress = wallet.freshReceiveAddress()
    val currentAddress = wallet.currentReceiveAddress()
    System.out.println(
      "currentReceiveAddress$currentAddress 
       freshAddress$freshAddress 
       changeAddress $changeAddress"
      )**strong text**
    }

从助记符或种子生成电子钱包,然后即可获取地址。而且,是的,它处于离线状态