Add deposit funds screen

This commit is contained in:
Manfred Karrer 2016-03-22 00:33:05 +01:00
parent 605cf27eaf
commit fa11cb4a6b
23 changed files with 675 additions and 37 deletions

View file

@ -499,7 +499,7 @@ public class DisputeManager {
contract.getBuyerPayoutAddressString(),
contract.getSellerPayoutAddressString(),
disputeResult.getArbitratorAddressAsString(),
walletService.getAddressEntryByOfferId(dispute.getTradeId()),
walletService.getTradeAddressEntry(dispute.getTradeId()),
contract.getBuyerBtcPubKey(),
contract.getSellerBtcPubKey(),
disputeResult.getArbitratorPubKey()

View file

@ -44,8 +44,10 @@ public final class AddressEntry implements Persistable {
private static final Logger log = LoggerFactory.getLogger(AddressEntry.class);
public enum Context {
SAVINGS,
TRADE,
ARBITRATOR
ARBITRATOR,
DAO
}
// keyPair can be null in case the object is created from deserialization as it is transient.

View file

@ -66,9 +66,16 @@ public final class AddressEntryList extends ArrayList<AddressEntry> implements P
}
}
public AddressEntry getNewAddressEntry(AddressEntry.Context context, String offerId) {
public AddressEntry getNewTradeAddressEntry(String offerId) {
log.trace("getNewAddressEntry called with offerId " + offerId);
AddressEntry addressEntry = new AddressEntry(wallet.freshReceiveKey(), wallet.getParams(), context, offerId);
AddressEntry addressEntry = new AddressEntry(wallet.freshReceiveKey(), wallet.getParams(), AddressEntry.Context.TRADE, offerId);
add(addressEntry);
storage.queueUpForSave();
return addressEntry;
}
public AddressEntry getNewSavingsAddressEntry() {
AddressEntry addressEntry = new AddressEntry(wallet.freshReceiveKey(), wallet.getParams(), AddressEntry.Context.SAVINGS);
add(addressEntry);
storage.queueUpForSave();
return addressEntry;

View file

@ -312,18 +312,28 @@ public class WalletService {
return ImmutableList.copyOf(addressEntryList);
}
public List<AddressEntry> getSavingsAddressEntryList() {
return getAddressEntryList().stream()
.filter(e -> e.getContext().equals(AddressEntry.Context.SAVINGS))
.collect(Collectors.toList());
}
public AddressEntry getArbitratorAddressEntry() {
return arbitratorAddressEntry;
}
public AddressEntry getAddressEntryByOfferId(String offerId) {
public AddressEntry getTradeAddressEntry(String offerId) {
Optional<AddressEntry> addressEntry = getAddressEntryList().stream()
.filter(e -> offerId.equals(e.getOfferId()))
.findAny();
if (addressEntry.isPresent())
return addressEntry.get();
else
return addressEntryList.getNewAddressEntry(AddressEntry.Context.TRADE, offerId);
return addressEntryList.getNewTradeAddressEntry(offerId);
}
public AddressEntry getNewSavingsAddressEntry() {
return addressEntryList.getNewSavingsAddressEntry();
}
private Optional<AddressEntry> getAddressEntryByAddress(String address) {

View file

@ -302,7 +302,7 @@ public class TradeManager {
///////////////////////////////////////////////////////////////////////////////////////////
public void onWithdrawRequest(String toAddress, KeyParameter aesKey, Trade trade, ResultHandler resultHandler, FaultHandler faultHandler) {
AddressEntry addressEntry = walletService.getAddressEntryByOfferId(trade.getId());
AddressEntry addressEntry = walletService.getTradeAddressEntry(trade.getId());
String fromAddress = addressEntry.getAddressString();
FutureCallback<Transaction> callback = new FutureCallback<Transaction>() {

View file

@ -45,7 +45,7 @@ public class BroadcastCreateOfferFeeTx extends Task<PlaceOfferModel> {
try {
runInterceptHook();
Coin totalsNeeded = FeePolicy.getSecurityDeposit().add(FeePolicy.getCreateOfferFee()).add(FeePolicy.getFixedTxFeeForTrades());
AddressEntry addressEntry = model.walletService.getAddressEntryByOfferId(model.offer.getId());
AddressEntry addressEntry = model.walletService.getTradeAddressEntry(model.offer.getId());
Coin balance = model.walletService.getBalanceForAddress(addressEntry.getAddress());
if (balance.compareTo(totalsNeeded) >= 0) {
model.tradeWalletService.broadcastTx(model.getTransaction(), new FutureCallback<Transaction>() {

View file

@ -44,7 +44,7 @@ public class CreateOfferFeeTx extends Task<PlaceOfferModel> {
log.debug("selectedArbitratorAddress " + selectedArbitratorNodeAddress);
Arbitrator selectedArbitrator = model.user.getAcceptedArbitratorByAddress(selectedArbitratorNodeAddress);
Transaction transaction = model.tradeWalletService.createTradingFeeTx(
model.walletService.getAddressEntryByOfferId(model.offer.getId()),
model.walletService.getTradeAddressEntry(model.offer.getId()),
FeePolicy.getCreateOfferFee(),
selectedArbitrator.getBtcAddress());

View file

@ -180,7 +180,7 @@ public class ProcessModel implements Model, Serializable {
}
public AddressEntry getAddressEntry() {
return walletService.getAddressEntryByOfferId(offer.getId());
return walletService.getTradeAddressEntry(offer.getId());
}
public byte[] getTradeWalletPubKey() {

View file

@ -51,7 +51,7 @@ public class SetupDepositBalanceListener extends TradeTask {
runInterceptHook();
WalletService walletService = processModel.getWalletService();
Address address = walletService.getAddressEntryByOfferId(trade.getId()).getAddress();
Address address = walletService.getTradeAddressEntry(trade.getId()).getAddress();
balanceListener = new BalanceListener(address) {
@Override
public void onBalanceChanged(Coin balance, Transaction tx) {