多鏈錢包系統(tǒng)開發(fā)(方案及邏輯)丨多鏈錢包開發(fā)案例及源碼
Is multi-chain wallet a multi-currency wallet? Multi-currency wallet:a wallet that supports multiple blockchain digital assets.Multiple blockchain digital assets can be a blockchain main chain and tokens set around the main chain protocol,or different digital assets on multiple blockchain main chains,so multi-chain wallets can also be said to be multi-currency wallets. NetworkParameters params=TestNet3Params.get(); DeterministicSeed seed=new DeterministicSeed(new SecureRandom(),128,"password",Utils.currentTimeSeconds()); Wallet wallet=Wallet.fromSeed(params,seed); DeterministicSeed的構(gòu)造方法:開發(fā)需求I35模式7O98源碼o7I8 public DeterministicSeed(SecureRandom random,int bits,String passphrase,long creationTimeSeconds){ this(getEntropy(random,bits),checkNotNull(passphrase),creationTimeSeconds); } 先來看看getEntropy函數(shù) private static byte[]getEntropy(SecureRandom random,int bits){ checkArgument(bits<=MAX_SEED_ENTROPY_BITS,"requested entropy size too large"); byte[]seed=new byte[bits/8];案例分析及開發(fā):mrsfu123 random.nextBytes(seed); return seed; } 可以看出通過getEntropy函數(shù)得到一個byte數(shù)組,然后作為參數(shù)傳給構(gòu)造方法2 public DeterministicSeed(byte[]entropy,String passphrase,long creationTimeSeconds){ //檢查參數(shù)的正確性 checkArgument(entropy.length%4==0,"entropy size in bits not divisible by 32"); checkArgument(entropy.length*8>=DEFAULT_SEED_ENTROPY_BITS,"entropy size too small"); checkNotNull(passphrase); try{ //生成助記詞 this.mnemonicCode=MnemonicCode.INSTANCE.toMnemonic(entropy); }catch(MnemonicException.MnemonicLengthException e){ //cannot happen throw new RuntimeException(e); } //通過助記詞生成種子,詳情看“通過助記詞生成種子” this.seed=MnemonicCode.toSeed(mnemonicCode,passphrase); this.encryptedMnemonicCode=null; this.creationTimeSeconds=creationTimeSeconds; }