@Override public List<AbstractAddress> getReceivedFrom() { return ImmutableList.of((AbstractAddress) new NxtAddress(type, tx.getSenderId())); }
public static String addressSplitToGroups(final NxtAddress address) { return address.toString(); // already split in groups }
@Override public boolean isAddressMine(AbstractAddress address) { return this.address.equals(address); }
@Test public void testHDAccountNxt() throws MnemonicException, UnreadableWalletException { DeterministicSeed seed = new DeterministicSeed(recoveryPhrase, null, "", 0); DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes()); DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey); DeterministicKey entropy = hierarchy.get(NxtMain.get().getBip44Path(0), false, true); NxtFamilyKey nxtKey = new NxtFamilyKey(entropy, null, null); byte[] privateKey = nxtKey.getPrivateKey(); byte[] publicKey = nxtKey.getPublicKey(); NxtAddress address = new NxtAddress(NxtMain.get(), publicKey); assertArrayEquals(nxtPrivateKey, privateKey); assertArrayEquals(nxtPublicKey, publicKey); assertEquals(nxtRsAddress, address.toString()); assertEquals(nxtAccountId, address.getAccountId()); }
public static NxtSendRequest to(NxtFamilyWallet from, NxtAddress destination, Value amount) { checkNotNull(destination.getType(), "Address is for an unknown network"); checkState(from.getCoinType() == destination.getType(), "Incompatible destination address coin type"); checkState(TypeUtils.is(destination.getType(), amount.type), "Incompatible sending amount type"); checkTypeCompatibility(destination.getType()); NxtSendRequest req = new NxtSendRequest(destination.getType()); byte version = (byte) 1; int timestamp; if (req.type instanceof NxtMain) { timestamp = Convert.toNxtEpochTime(System.currentTimeMillis()); } else if (req.type instanceof BurstMain) { timestamp = Convert.toBurstEpochTime(System.currentTimeMillis()); } else { throw new RuntimeException("Unexpected NXT family type: " + req.type.toString()); } TransactionImpl.BuilderImpl builder = new TransactionImpl.BuilderImpl(version, from.getPublicKey(), amount.value, req.fee.value, timestamp, NxtFamily.DEFAULT_DEADLINE, Attachment.ORDINARY_PAYMENT); builder.recipientId(destination.getAccountId()); // TODO extra check, query the server if the public key announcement is actually needed if (destination.getPublicKey() != null) { Appendix.PublicKeyAnnouncement publicKeyAnnouncement = new Appendix.PublicKeyAnnouncement(destination.getPublicKey()); builder.publicKeyAnnouncement(publicKeyAnnouncement); } req.nxtTxBuilder = builder; return req; }
@Test public void testHDAccountNxt() throws MnemonicException { byte[] privateKey = nxtAccount.rootKey.getPrivateKey(); byte[] publicKey = nxtAccount.getPublicKey(); assertArrayEquals(nxtPrivateKey, privateKey); assertEquals(nxtRsAddress, nxtAccount.getPublicKeyMnemonic()); assertArrayEquals(nxtPublicKey, publicKey); NxtAddress address = (NxtAddress) nxtAccount.getReceiveAddress(); assertEquals(nxtRsAddress, address.toString()); assertEquals(nxtAccountId, address.getAccountId()); }
@Test public void testAltChainsConvertToCoinURI() throws Exception { byte[] hash160 = BitAddress.from(BitcoinMain.get(), MAINNET_GOOD_ADDRESS).getHash160(); String goodAddressStr; BitAddress goodAddress; // Litecoin goodAddress = BitAddress.from(LTC, hash160); goodAddressStr = goodAddress.toString(); assertEquals("litecoin:" + goodAddressStr + "?amount=12.34&label=Hello&message=AMessage", CoinURI.convertToCoinURI(goodAddress, LTC.value("12.34"), "Hello", "AMessage")); // Dogecoin goodAddress = BitAddress.from(DOGE, hash160); goodAddressStr = goodAddress.toString(); assertEquals("dogecoin:" + goodAddressStr + "?amount=12.34&label=Hello&message=AMessage", CoinURI.convertToCoinURI(goodAddress, DOGE.value("12.34"), "Hello", "AMessage")); // Peercoin goodAddress = BitAddress.from(PPC, hash160); goodAddressStr = goodAddress.toString(); assertEquals("peercoin:" + goodAddressStr + "?amount=12.34&label=Hello&message=AMessage", CoinURI.convertToCoinURI(goodAddress, PPC.value("12.34"), "Hello", "AMessage")); // Darkcoin goodAddress = BitAddress.from(DASH, hash160); goodAddressStr = goodAddress.toString(); assertEquals("dash:" + goodAddressStr + "?amount=12.34&label=Hello&message=AMessage", CoinURI.convertToCoinURI(goodAddress, DASH.value("12.34"), "Hello", "AMessage")); // NXT String pubkeyStr = "3c1c0b3f8f87d6efdc2694ce43f848375a4f761624d255e5fc1194a4ebc76755"; byte[] pubkey = Hex.decode(pubkeyStr); NxtAddress nxtGoodAddress = new NxtAddress(NXT, pubkey); goodAddressStr = nxtGoodAddress.toString(); assertEquals("nxt:" + goodAddressStr + "?amount=12.34&label=Hello&message=AMessage&pubkey="+pubkeyStr, CoinURI.convertToCoinURI(nxtGoodAddress, NXT.value("12.34"), "Hello", "AMessage", pubkeyStr)); }
@Test public void testNxtTransaction() throws WalletAccount.WalletAccountException, NxtException.ValidationException { NxtAddress destination = (NxtAddress) otherAccount.getReceiveAddress(); Value amount = NXT.value("1"); NxtSendRequest req = nxtAccount.sendCoinsOffline(destination, amount); nxtAccount.completeAndSignTx(req); Transaction nxtTx = req.nxtTxBuilder.build(); // nxtTx.sign(nxtSecret); byte[] txBytes = req.nxtTxBuilder.build().getBytes(); req.tx = new NxtTransaction(NXT, req.nxtTxBuilder.build()); Transaction parsedTx = TransactionImpl.parseTransaction(txBytes); assertEquals(Attachment.ORDINARY_PAYMENT, parsedTx.getAttachment()); assertEquals(NxtFamily.DEFAULT_DEADLINE, parsedTx.getDeadline()); assertEquals((req.tx.getRawTransaction()).getTimestamp(), parsedTx.getTimestamp()); assertEquals(nxtAccountId, parsedTx.getSenderId()); assertArrayEquals(nxtPublicKey, parsedTx.getSenderPublicKey()); assertEquals(amount.value, parsedTx.getAmountNQT()); assertEquals(req.fee.value, parsedTx.getFeeNQT()); assertEquals(destination.getAccountId(), parsedTx.getRecipientId()); // System.out.println(Convert.toHexString(nxtTx.getBytes())); // TODO check signature }
@Override public String getPublicKeyMnemonic() { return address.getRsAccount(); }
@Override public AbstractAddress newAddress(String addressStr) throws AddressMalformedException { return NxtAddress.fromString(this, addressStr); }
public static NxtSendRequest emptyWallet(NxtFamilyWallet from, NxtAddress destination) { checkNotNull(destination.getType(), "Address is for an unknown network"); checkState(destination.getType().getFeePolicy() == FeePolicy.FLAT_FEE, "Only flat fee is supported"); Value allFundsMinusFee = from.getBalance().subtract(destination.getType().getFeeValue()); return to(from, destination, allFundsMinusFee); }
@Override public String toString() { return getRsAccount(); }
public NxtFamilyWallet(String id, NxtFamilyKey key, CoinType type) { super(type, id); rootKey = key; address = new NxtAddress(type, key.getPublicKey()); balance = type.value(0); addressesStatus = new HashMap<>(); addressesSubscribed = new ArrayList<>(); addressesPendingSubscription = new ArrayList<>(); statusPendingUpdates = new HashMap<>(); //fetchingTransactions = new HashSet<>(); rawtransactions = new HashMap<>(); listeners = new CopyOnWriteArrayList<>(); }
@Override public List<AbstractOutput> getSentTo() { return ImmutableList.of(new AbstractOutput(new NxtAddress(type, tx.getRecipientId()), Value.valueOf(type, tx.getAmountNQT()))); }
public static NxtAddress fromString(CoinType type, String address) throws AddressMalformedException { try { return new NxtAddress(type, Crypto.rsDecode(address.replace(type.getAddressPrefix(), "")), address); } catch (Exception e) { throw new AddressMalformedException(e); } }
if (possibleType instanceof NxtFamily) { try { address = new NxtAddress(possibleType, addressToken); putWithValidation(FIELD_ADDRESS, address); break;