private static String getWalletFileName(WalletFile walletFile) { DateTimeFormatter format = DateTimeFormatter.ofPattern( "'UTC--'yyyy-MM-dd'T'HH-mm-ss.nVV'--'"); ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC); return now.format(format) + walletFile.getAddress() + ".json"; }
@Override public int hashCode() { int result = getAddress() != null ? getAddress().hashCode() : 0; result = 31 * result + (getCrypto() != null ? getCrypto().hashCode() : 0); result = 31 * result + (getId() != null ? getId().hashCode() : 0); result = 31 * result + version; return result; }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof WalletFile)) { return false; } WalletFile that = (WalletFile) o; if (getAddress() != null ? !getAddress().equals(that.getAddress()) : that.getAddress() != null) { return false; } if (getCrypto() != null ? !getCrypto().equals(that.getCrypto()) : that.getCrypto() != null) { return false; } if (getId() != null ? !getId().equals(that.getId()) : that.getId() != null) { return false; } return version == that.version; }
private void testCreate(WalletFile walletFile) throws Exception { assertThat(walletFile.getAddress(), is(SampleKeys.ADDRESS_NO_PREFIX)); }
private static String getWalletFileName(WalletFile walletFile) { SimpleDateFormat dateFormat = new SimpleDateFormat("'UTC--'yyyy-MM-dd'T'HH-mm-ss.SSS'--'"); return dateFormat.format(new Date()) + walletFile.getAddress() + ".json"; }
@Override public void onWalletLoaded(WalletFile w) { mWalletFile = w; Log.d(TAG, "onWalletLoaded: " + mWalletFile.getAddress().length()); mAddress = HEX_PREFIX + mWalletFile.getAddress(); runOnUiThread(new Runnable() { @Override public void run() { mWalletAddressText.setText(mAddress); updateBalance(); } }); } });
public void onImportMnemonics(View view) throws CipherException, MnemonicException.MnemonicLengthException, MnemonicException.MnemonicWordException, MnemonicException.MnemonicChecksumException { String s = importMnemonicEdit.getText().toString().trim(); String[] split = s.split(","); ArrayList<String> list = new ArrayList<>(); for (String one : split) { String word = one.trim(); list.add(word); } WalletFile walletFile = createWalletFile(list); String address = "0x" + walletFile.getAddress(); importWalletAddress.setText(address); } }
/** * 创建钱包 * * @param password 密码 */ public static void createWallet(String password) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, CipherException, JsonProcessingException { WalletFile walletFile; ECKeyPair ecKeyPair = Keys.createEcKeyPair(); walletFile = Wallet.createStandard(password, ecKeyPair); System.out.println("address " + walletFile.getAddress()); ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); String jsonStr = objectMapper.writeValueAsString(walletFile); System.out.println("keystore json file " + jsonStr); }
public void onCreateMnemonicWallet(View view) { // List<String> wordList = MnemonicCode.INSTANCE.getWordList(); try { List<String> words = createMnemonics(); mnemonicEdit.setText(words.toString()); WalletFile light = createWalletFile(words); String address = "0x" + light.getAddress(); walletAddressEdit.setText(address); } catch (MnemonicException.MnemonicLengthException e) { e.printStackTrace(); } catch (MnemonicException.MnemonicChecksumException e) { e.printStackTrace(); } catch (MnemonicException.MnemonicWordException e) { e.printStackTrace(); } catch (CipherException e) { e.printStackTrace(); } }
try { WalletFile walletFile = Wallet.createLight(password, keyPair); System.out.println("eth address " + "0x" + walletFile.getAddress()); ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); keyPair.getPublicKey().toString(16), mnemonic, dkKey.getPathAsString(), "0x" + walletFile.getAddress(), jsonStr); } catch (CipherException | JsonProcessingException e) { e.printStackTrace();