Adapts a Ripple Account to an XChange Wallet object.
969629
public static AccountInfo adaptAccountInfo(
      final RippleAccountBalances account, final String username) {

    // Adapt account balances to XChange balances
    final Map<String, List<Balance>> balances = new HashMap<>();
    for (final RippleBalance balance : account.getBalances()) {
      final String walletId;
      if (balance.getCurrency().equals("XRP")) {
        walletId = null;
      } else {
        walletId = balance.getCounterparty();
      }
      if (!balances.containsKey(walletId)) {
        balances.put(walletId, new LinkedList<Balance>());
      }
      balances
          .get(walletId)
          .add(new Balance(Currency.getInstance(balance.getCurrency()), balance.getValue()));
    }

    final List<Wallet> accountInfo = new ArrayList<>(balances.size());
    for (final Map.Entry<String, List<Balance>> wallet : balances.entrySet()) {
      accountInfo.add(new Wallet(wallet.getKey(), wallet.getValue()));
    }

    return new AccountInfo(username, BigDecimal.ZERO, accountInfo);
  }
1256340
def from_xdr_object(cls, op_xdr_object):
        
        if not op_xdr_object.sourceAccount:
            source = None
        else:
            source = encode_check(
                'account', op_xdr_object.sourceAccount[0].ed25519).decode()

        destination = encode_check(
            'account',
            op_xdr_object.body.createAccountOp.destination.ed25519).decode()
        starting_balance = Operation.from_xdr_amount(
            op_xdr_object.body.createAccountOp.startingBalance)

        return cls(
            source=source,
            destination=destination,
            starting_balance=starting_balance,
        )
851044
def to_xdr_object(self):
        
        trustor = account_xdr_object(self.trustor)
        length = len(self.asset_code)
        assert length <= 12
        pad_length = 4 - length if length <= 4 else 12 - length
        # asset_code = self.asset_code + '\x00' * pad_length
        # asset_code = bytearray(asset_code, encoding='utf-8')
        asset_code = bytearray(self.asset_code, 'ascii') + b'\x00' * pad_length
        asset = Xdr.nullclass()
        if len(asset_code) == 4:
            asset.type = Xdr.const.ASSET_TYPE_CREDIT_ALPHANUM4
            asset.assetCode4 = asset_code
        else:
            asset.type = Xdr.const.ASSET_TYPE_CREDIT_ALPHANUM12
            asset.assetCode12 = asset_code

        allow_trust_op = Xdr.types.AllowTrustOp(trustor, asset, self.authorize)
        self.body.type = Xdr.const.ALLOW_TRUST
        self.body.allowTrustOp = allow_trust_op
        return super(AllowTrust, self).to_xdr_object()
969054
@Path("/{accountSid}")
    @Consumes(APPLICATION_FORM_URLENCODED)
    @POST
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public Response updateAccountAsXmlPost(@PathParam("accountSid") final String accountSid,
            final MultivaluedMap<String, String> data,
            @HeaderParam("Accept") String accept,
            @Context SecurityContext sec) {
        return updateAccount(accountSid, data, retrieveMediaType(accept), ContextUtil.convert(sec));
    }
1344468
public static String adaptCurrencyPair(CurrencyPair currencyPair) {
    return currencyPair.base.getCurrencyCode().toLowerCase()
        + currencyPair.counter.getCurrencyCode().toLowerCase();
  }
169118
def normalise(self, to_currency):
        
        out = Money(currency=to_currency)
        for money in self._money_obs:
            out += converter.convert(money, to_currency)
        return Balance([out])
1136912
def from_xdr_object(cls, op_xdr_object):
        
        if not op_xdr_object.sourceAccount:
            source = None
        else:
            source = encode_check(
                'account', op_xdr_object.sourceAccount[0].ed25519).decode()

        selling = Asset.from_xdr_object(
            op_xdr_object.body.createPassiveOfferOp.selling)
        buying = Asset.from_xdr_object(
            op_xdr_object.body.createPassiveOfferOp.buying)
        amount = Operation.from_xdr_amount(
            op_xdr_object.body.createPassiveOfferOp.amount)

        n = op_xdr_object.body.createPassiveOfferOp.price.n
        d = op_xdr_object.body.createPassiveOfferOp.price.d
        price = division(n, d)
        return cls(
            source=source,
            selling=selling,
            buying=buying,
            amount=amount,
            price=price)
640822
public static Wallet adaptWallet(Map<String, ANXWallet> anxWallets) {

    List<Balance> balances = new ArrayList<>();

    for (ANXWallet anxWallet : anxWallets.values()) {
      Balance balance = adaptBalance(anxWallet);
      if (balance != null) {
        balances.add(balance);
      }
    }
    return new Wallet(balances);
  }
570245
def exchange(original, target, amount)
      negative = (@numeric < 0)

      rate = call_xavier_api(original, target)
     #
      # Get the result and round it to 2 decimals
      result = sprintf("%.2f", amount * rate).to_f

      return -(result) if negative
      result
    end
656419
function addNewAddress(wallet, is_change, address_index, address, handleError){
	breadcrumbs.add('addNewAddress is_change='+is_change+', index='+address_index+', address='+address);
	db.query("SELECT 1 FROM wallets WHERE wallet=?", [wallet], function(rows){
		if (rows.length === 0)
			return handleError("wallet "+wallet+" does not exist");
		deriveAddress(wallet, is_change, address_index, function(new_address, arrDefinition){
			if (new_address !== address)
				return handleError("I derived address "+new_address+", your address "+address);
			recordAddress(wallet, is_change, address_index, address, arrDefinition, function(){
				eventBus.emit("new_wallet_address", address);
				handleError();
			});
		});
	});
}
614806
public static Trade adaptTrade(BTCTurkTrades btcTurkTrade, CurrencyPair currencyPair) {

    return new Trade(
        null,
        btcTurkTrade.getAmount(),
        currencyPair,
        btcTurkTrade.getPrice(),
        btcTurkTrade.getDate(),
        btcTurkTrade.getTid().toString());
  }
1295959
def from_xdr_object(cls, op_xdr_object):
        
        if not op_xdr_object.sourceAccount:
            source = None
        else:
            source = encode_check(
                'account', op_xdr_object.sourceAccount[0].ed25519).decode()
        trustor = encode_check(
            'account',
            op_xdr_object.body.allowTrustOp.trustor.ed25519).decode()
        authorize = op_xdr_object.body.allowTrustOp.authorize

        asset_type = op_xdr_object.body.allowTrustOp.asset.type
        if asset_type == Xdr.const.ASSET_TYPE_CREDIT_ALPHANUM4:
            asset_code = (
                op_xdr_object.body.allowTrustOp.asset.assetCode4.decode())
        elif asset_type == Xdr.const.ASSET_TYPE_CREDIT_ALPHANUM12:
            asset_code = (
                op_xdr_object.body.allowTrustOp.asset.assetCode12.decode())
        else:
            raise NotImplementedError(
                "Operation of asset_type={} is not implemented"
                ".".format(asset_type.type))

        return cls(
            source=source,
            trustor=trustor,
            authorize=authorize,
            asset_code=asset_code)
1357346
def from_xdr_object(cls, op_xdr_object):
        
        if not op_xdr_object.sourceAccount:
            source = None
        else:
            source = encode_check(
                'account', op_xdr_object.sourceAccount[0].ed25519).decode()

        destination = encode_check(
            'account',
            op_xdr_object.body.pathPaymentOp.destination.ed25519).decode()
        send_asset = Asset.from_xdr_object(
            op_xdr_object.body.pathPaymentOp.sendAsset)
        dest_asset = Asset.from_xdr_object(
            op_xdr_object.body.pathPaymentOp.destAsset)
        send_max = Operation.from_xdr_amount(
            op_xdr_object.body.pathPaymentOp.sendMax)
        dest_amount = Operation.from_xdr_amount(
            op_xdr_object.body.pathPaymentOp.destAmount)

        path = []
        if op_xdr_object.body.pathPaymentOp.path:
            for x in op_xdr_object.body.pathPaymentOp.path:
                path.append(Asset.from_xdr_object(x))

        return cls(
            source=source,
            destination=destination,
            send_asset=send_asset,
            send_max=send_max,
            dest_asset=dest_asset,
            dest_amount=dest_amount,
            path=path)
248195
def sell(self, account_id, **params):
        """"""
        if 'amount' not in params and 'total' not in params:
            raise ValueError("Missing required parameter: 'amount' or 'total'")
        for required in ['currency']:
            if required not in params:
                raise ValueError("Missing required parameter: %s" % required)
        response = self._post('v2', 'accounts', account_id, 'sells', data=params)
        return self._make_api_object(response, Sell)
154667
public static Ticker adaptTicker(CampBXTicker campbxTicker, CurrencyPair currencyPair) {

    BigDecimal last = campbxTicker.getLast();
    BigDecimal bid = campbxTicker.getBid();
    BigDecimal ask = campbxTicker.getAsk();

    return new Ticker.Builder().currencyPair(currencyPair).last(last).bid(bid).ask(ask).build();
  }
1315572
@Override
  public AccountInfo getAccountInfo() throws IOException {
    final RippleAccountBalances account = getRippleAccountBalances();
    final String username = exchange.getExchangeSpecification().getApiKey();
    return RippleAdapters.adaptAccountInfo(account, username);
  }
1116595
function createSinglesigWallet(xPubKey, account, walletName, handleWallet){
	if(walletName.indexOf("(*)") >= 0)
		var arrDefinitionTemplate = ["sig", {pubkey: '$pubkey@'+device.getMyColdDeviceAddress()}];
	else
		var arrDefinitionTemplate = ["sig", {pubkey: '$pubkey@'+device.getMyDeviceAddress()}];
	createWallet(xPubKey, account, arrDefinitionTemplate, walletName, handleWallet);
}