void processAsset(Asset& asset, AssetType assetType, std::string const& issuerStr, soci::indicator const& issuerIndicator, std::string const& assetCode, soci::indicator const& assetCodeIndicator) { asset.type(assetType); if (assetType != ASSET_TYPE_NATIVE) { if ((assetCodeIndicator != soci::i_ok) || (issuerIndicator != soci::i_ok)) { throw std::runtime_error("bad database state"); } if (assetType == ASSET_TYPE_CREDIT_ALPHANUM12) { asset.alphaNum12().issuer = KeyUtils::fromStrKey<PublicKey>(issuerStr); strToAssetCode(asset.alphaNum12().assetCode, assetCode); } else if (assetType == ASSET_TYPE_CREDIT_ALPHANUM4) { asset.alphaNum4().issuer = KeyUtils::fromStrKey<PublicKey>(issuerStr); strToAssetCode(asset.alphaNum4().assetCode, assetCode); } else { throw std::runtime_error("bad database state"); } } }
void OfferFrame::loadOffers(StatementContext& prep, std::function<void(LedgerEntry const&)> offerProcessor) { string actIDStrKey; unsigned int sellingAssetType, buyingAssetType; std::string sellingAssetCode, buyingAssetCode, sellingIssuerStrKey, buyingIssuerStrKey; soci::indicator sellingAssetCodeIndicator, buyingAssetCodeIndicator, sellingIssuerIndicator, buyingIssuerIndicator; LedgerEntry le; le.data.type(OFFER); OfferEntry& oe = le.data.offer(); statement& st = prep.statement(); st.exchange(into(actIDStrKey)); st.exchange(into(oe.offerID)); st.exchange(into(sellingAssetType)); st.exchange(into(sellingAssetCode, sellingAssetCodeIndicator)); st.exchange(into(sellingIssuerStrKey, sellingIssuerIndicator)); st.exchange(into(buyingAssetType)); st.exchange(into(buyingAssetCode, buyingAssetCodeIndicator)); st.exchange(into(buyingIssuerStrKey, buyingIssuerIndicator)); st.exchange(into(oe.amount)); st.exchange(into(oe.price.n)); st.exchange(into(oe.price.d)); st.exchange(into(oe.flags)); st.exchange(into(le.lastModifiedLedgerSeq)); st.define_and_bind(); st.execute(true); while (st.got_data()) { oe.sellerID = PubKeyUtils::fromStrKey(actIDStrKey); if ((buyingAssetType > ASSET_TYPE_CREDIT_ALPHANUM12) || (sellingAssetType > ASSET_TYPE_CREDIT_ALPHANUM12)) throw std::runtime_error("bad database state"); oe.buying.type((AssetType)buyingAssetType); oe.selling.type((AssetType)sellingAssetType); if (sellingAssetType != ASSET_TYPE_NATIVE) { if ((sellingAssetCodeIndicator != soci::i_ok) || (sellingIssuerIndicator != soci::i_ok)) { throw std::runtime_error("bad database state"); } if (sellingAssetType == ASSET_TYPE_CREDIT_ALPHANUM12) { oe.selling.alphaNum12().issuer = PubKeyUtils::fromStrKey(sellingIssuerStrKey); strToAssetCode(oe.selling.alphaNum12().assetCode, sellingAssetCode); } else if (sellingAssetType == ASSET_TYPE_CREDIT_ALPHANUM4) { oe.selling.alphaNum4().issuer = PubKeyUtils::fromStrKey(sellingIssuerStrKey); strToAssetCode(oe.selling.alphaNum4().assetCode, sellingAssetCode); } } if (buyingAssetType != ASSET_TYPE_NATIVE) { if ((buyingAssetCodeIndicator != soci::i_ok) || (buyingIssuerIndicator != soci::i_ok)) { throw std::runtime_error("bad database state"); } if (buyingAssetType == ASSET_TYPE_CREDIT_ALPHANUM12) { oe.buying.alphaNum12().issuer = PubKeyUtils::fromStrKey(buyingIssuerStrKey); strToAssetCode(oe.buying.alphaNum12().assetCode, buyingAssetCode); } else if (buyingAssetType == ASSET_TYPE_CREDIT_ALPHANUM4) { oe.buying.alphaNum4().issuer = PubKeyUtils::fromStrKey(buyingIssuerStrKey); strToAssetCode(oe.buying.alphaNum4().assetCode, buyingAssetCode); } } if (!isValid(oe)) { throw std::runtime_error("Invalid asset"); } offerProcessor(le); st.fetch(); } }
void OfferFrame::loadOffers(soci::details::prepare_temp_type& prep, std::function<void(LedgerEntry const&)> offerProcessor) { string actIDStrKey; unsigned int sellingAssetType, buyingAssetType; std::string sellingAssetCode, buyingAssetCode, sellingIssuerStrKey, buyingIssuerStrKey; soci::indicator sellingAssetCodeIndicator, buyingAssetCodeIndicator, sellingIssuerIndicator, buyingIssuerIndicator; LedgerEntry le; le.type(OFFER); OfferEntry& oe = le.offer(); statement st = (prep, into(actIDStrKey), into(oe.offerID), into(sellingAssetType), into(sellingAssetCode, sellingAssetCodeIndicator), into(sellingIssuerStrKey, sellingIssuerIndicator), into(buyingAssetType), into(buyingAssetCode, buyingAssetCodeIndicator), into(buyingIssuerStrKey, buyingIssuerIndicator), into(oe.amount), into(oe.price.n), into(oe.price.d), into(oe.flags)); st.execute(true); while(st.got_data()) { oe.sellerID = PubKeyUtils::fromStrKey(actIDStrKey); if( (buyingAssetType > ASSET_TYPE_CREDIT_ALPHANUM12) || (sellingAssetType > ASSET_TYPE_CREDIT_ALPHANUM12) ) throw std::runtime_error("bad database state"); oe.buying.type((AssetType)buyingAssetType); oe.selling.type((AssetType)sellingAssetType); if(sellingAssetType != ASSET_TYPE_NATIVE) { if((sellingAssetCodeIndicator != soci::i_ok) || (sellingIssuerIndicator != soci::i_ok)) { throw std::runtime_error("bad database state"); } if(sellingAssetType == ASSET_TYPE_CREDIT_ALPHANUM12) { oe.selling.alphaNum12().issuer = PubKeyUtils::fromStrKey(sellingIssuerStrKey); strToAssetCode(oe.selling.alphaNum12().assetCode, sellingAssetCode); } else if(sellingAssetType == ASSET_TYPE_CREDIT_ALPHANUM4) { oe.selling.alphaNum4().issuer = PubKeyUtils::fromStrKey(sellingIssuerStrKey); strToAssetCode(oe.selling.alphaNum4().assetCode, sellingAssetCode); } } if(buyingAssetType != ASSET_TYPE_NATIVE) { if((buyingAssetCodeIndicator != soci::i_ok) || (buyingIssuerIndicator != soci::i_ok)) { throw std::runtime_error("bad database state"); } if(buyingAssetType == ASSET_TYPE_CREDIT_ALPHANUM12) { oe.buying.alphaNum12().issuer = PubKeyUtils::fromStrKey(buyingIssuerStrKey); strToAssetCode(oe.buying.alphaNum12().assetCode, buyingAssetCode); } else if(buyingAssetType == ASSET_TYPE_CREDIT_ALPHANUM4) { oe.buying.alphaNum4().issuer = PubKeyUtils::fromStrKey(buyingIssuerStrKey); strToAssetCode(oe.buying.alphaNum4().assetCode, buyingAssetCode); } } offerProcessor(le); st.fetch(); } }