Search in sources :

Example 1 with Storable

use of org.opentransactions.otapi.Storable in project otapij by FellowTraveler.

the class Basket method getRegisteredAssets.

public static List getRegisteredAssets(String serverID, String nymID) {
    System.out.println("getRegisteredAssets - serverID:" + serverID + " nymID:" + nymID);
    List registeredAssetsList = null;
    // output will go here.
    String strEncodedObj = null;
    // we are about to create this object
    StringMap stringMap = null;
    Storable storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_STRING_MAP);
    if (storable != null) {
        stringMap = StringMap.ot_dynamic_cast(storable);
        if (stringMap != null) {
            // ADD ALL THE ASSET IDs HERE (To the string map, so you
            // can ask the server about them...)
            //
            int count = otapiJNI.OTAPI_Basic_GetAssetTypeCount();
            System.out.println(" count:" + count);
            for (int i = 0; i < count; i++) {
                String key = otapiJNI.OTAPI_Basic_GetAssetType_ID(i);
                System.out.println("key:" + key);
                stringMap.SetValue(key, "exists");
            }
            System.out.println(" BEFORE ENCODE,stringMap:" + stringMap);
            strEncodedObj = otapi.EncodeObject(stringMap);
        }
    }
    System.out.println(" fter ENCODE,strEncodedObj:" + strEncodedObj);
    if (!Utility.VerifyStringVal(strEncodedObj)) {
        System.out.println("strEncodedObj is null");
        return null;
    //Error;
    }
    // Then send the server message
    OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.QUERY_ASSET_TYPES, serverID, nymID, strEncodedObj);
    System.out.println(" theRequest :" + theRequest);
    String strResponse = theRequest.SendRequest(theRequest, "QUERY_ASSET_TYPES");
    System.out.println(" strResponse:" + strResponse);
    String strReplyMap = null;
    if (Utility.VerifyStringVal(strResponse)) {
        strReplyMap = otapiJNI.OTAPI_Basic_Message_GetPayload(strResponse);
    }
    System.out.println("strResponse is " + strResponse);
    if (Utility.VerifyStringVal(strReplyMap)) {
        StringMap stringMapOutput = null;
        storable = otapi.DecodeObject(StoredObjectType.STORED_OBJ_STRING_MAP, strReplyMap);
        if (storable != null) {
            stringMapOutput = StringMap.ot_dynamic_cast(storable);
            if (stringMapOutput != null) {
                // Loop through string map. For each asset ID key, the value will
                // say either "true" or "false".
                int count = otapiJNI.OTAPI_Basic_GetAssetTypeCount();
                for (int i = 0; i < count; i++) {
                    String key = otapiJNI.OTAPI_Basic_GetAssetType_ID(i);
                    System.out.println("key in output:" + key);
                    String isRegistered = stringMapOutput.GetValue(key);
                    System.out.println("isRegistered in output:" + isRegistered);
                    if ("true".equalsIgnoreCase(isRegistered)) {
                        if (registeredAssetsList == null) {
                            registeredAssetsList = new ArrayList();
                        }
                        registeredAssetsList.add(key);
                    }
                }
            }
        }
    }
    System.out.println("registeredAssetsList is " + registeredAssetsList);
    return registeredAssetsList;
}
Also used : StringMap(org.opentransactions.otapi.StringMap) OTAPI_Func(com.moneychanger.core.util.OTAPI_Func) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Storable(org.opentransactions.otapi.Storable)

Example 2 with Storable

use of org.opentransactions.otapi.Storable in project otapij by FellowTraveler.

the class Helpers method getMarketList.

public static MarketList getMarketList(String serverID) {
    MarketList marketList = null;
    Storable storable = null;
    if (otapi.Exists("markets", serverID, "market_data.bin")) {
        storable = otapi.QueryObject(StoredObjectType.STORED_OBJ_MARKET_LIST, "markets", serverID, "market_data.bin");
        if (storable == null) {
            return null;
        }
        marketList = MarketList.ot_dynamic_cast(storable);
    } else {
        storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_MARKET_LIST);
        if (storable == null) {
            return null;
        }
        marketList = MarketList.ot_dynamic_cast(storable);
    }
    return marketList;
}
Also used : MarketList(org.opentransactions.otapi.MarketList) Storable(org.opentransactions.otapi.Storable)

Example 3 with Storable

use of org.opentransactions.otapi.Storable in project otapij by FellowTraveler.

the class Helpers method getNYMTrades.

public static TradeListNym getNYMTrades(String serverID, String nymID) {
    TradeListNym tradeListNym = null;
    Storable storable = null;
    if (otapi.Exists("nyms", "trades", serverID, nymID)) {
        storable = otapi.QueryObject(StoredObjectType.STORED_OBJ_TRADE_LIST_NYM, "nyms", "trades", serverID, nymID);
        if (storable == null) {
            return null;
        }
        tradeListNym = TradeListNym.ot_dynamic_cast(storable);
    } else {
        storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_TRADE_LIST_NYM);
        if (storable == null) {
            return null;
        }
        tradeListNym = TradeListNym.ot_dynamic_cast(storable);
    }
    return tradeListNym;
}
Also used : TradeListNym(org.opentransactions.otapi.TradeListNym) Storable(org.opentransactions.otapi.Storable)

Example 4 with Storable

use of org.opentransactions.otapi.Storable in project otapij by FellowTraveler.

the class Helpers method getAddressBook.

public static AddressBook getAddressBook() {
    AddressBook addressBook = null;
    Storable storable = null;
    if (otapi.Exists("moneychanger", "gui_contacts.dat")) {
        storable = otapi.QueryObject(StoredObjectType.STORED_OBJ_ADDRESS_BOOK, "moneychanger", "gui_contacts.dat");
        if (storable == null) {
            return null;
        }
        addressBook = AddressBook.ot_dynamic_cast(storable);
    } else {
        storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_ADDRESS_BOOK);
        if (storable == null) {
            return null;
        }
        addressBook = AddressBook.ot_dynamic_cast(storable);
    }
    return addressBook;
}
Also used : AddressBook(org.opentransactions.otapi.AddressBook) Storable(org.opentransactions.otapi.Storable)

Example 5 with Storable

use of org.opentransactions.otapi.Storable in project otapij by FellowTraveler.

the class Helpers method getMarketOffer.

public static OfferListMarket getMarketOffer(String serverID, String marketID) {
    OfferListMarket offerListMarket = null;
    Storable storable = null;
    if (otapi.Exists("markets", serverID, "offers", marketID + ".bin")) {
        storable = otapi.QueryObject(StoredObjectType.STORED_OBJ_OFFER_LIST_MARKET, "markets", serverID, "offers", marketID + ".bin");
        if (storable == null) {
            return null;
        }
        offerListMarket = OfferListMarket.ot_dynamic_cast(storable);
    } else {
        storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_OFFER_LIST_MARKET);
        if (storable == null) {
            return null;
        }
        offerListMarket = OfferListMarket.ot_dynamic_cast(storable);
    }
    return offerListMarket;
}
Also used : OfferListMarket(org.opentransactions.otapi.OfferListMarket) Storable(org.opentransactions.otapi.Storable)

Aggregations

Storable (org.opentransactions.otapi.Storable)14 AddressBook (org.opentransactions.otapi.AddressBook)4 Contact (org.opentransactions.otapi.Contact)3 WalletData (org.opentransactions.otapi.WalletData)3 StringMap (org.opentransactions.otapi.StringMap)2 OTAPI_Func (com.moneychanger.core.util.OTAPI_Func)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BitcoinServer (org.opentransactions.otapi.BitcoinServer)1 ContactAcct (org.opentransactions.otapi.ContactAcct)1 ContactNym (org.opentransactions.otapi.ContactNym)1 MarketList (org.opentransactions.otapi.MarketList)1 OfferListMarket (org.opentransactions.otapi.OfferListMarket)1 OfferListNym (org.opentransactions.otapi.OfferListNym)1 RippleServer (org.opentransactions.otapi.RippleServer)1 ServerInfo (org.opentransactions.otapi.ServerInfo)1 TradeListMarket (org.opentransactions.otapi.TradeListMarket)1 TradeListNym (org.opentransactions.otapi.TradeListNym)1