Search in sources :

Example 6 with Storable

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

the class AddressBookHelper method createContactAccount.

public static boolean createContactAccount(int index, String contactID, String label, String nymID, String acctID, String assetID, String serverID, String serverType, String publickey, String memo) {
    System.out.println("createContactAccount contactID:" + contactID);
    boolean status = false;
    AddressBook addressBook = Helpers.getAddressBook();
    if (addressBook == null) {
        System.out.println("createContactAccount - addressBook returns null");
        return false;
    }
    int count = (int) addressBook.GetContactCount();
    for (int i = 0; i < count; i++) {
        Contact contact = addressBook.GetContact(i);
        if (contact == null) {
            continue;
        }
        if (contactID.equals(contact.getContact_id())) {
            System.out.println("createContactAccount - contactID matches, index=" + index);
            ContactAcct contactAcct = null;
            if (index == -1) {
                System.out.println("createContactAccount new obj");
                Storable storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_CONTACT_ACCT);
                if (storable != null) {
                    contactAcct = ContactAcct.ot_dynamic_cast(storable);
                }
            } else {
                contactAcct = contact.GetContactAcct(index);
                System.out.println("createContactAccount old obj, contactAcct :" + contactAcct);
            }
            if (contactAcct != null) {
                contactAcct.setGui_label(label);
                contactAcct.setMemo(memo);
                contactAcct.setNym_id(nymID);
                contactAcct.setAcct_id(acctID);
                contactAcct.setAsset_type_id(assetID);
                contactAcct.setPublic_key(publickey);
                contactAcct.setServer_id(serverID);
                contactAcct.setServer_type(serverType);
                contact.AddContactAcct(contactAcct);
                status = otapi.StoreObject(addressBook, "moneychanger", "gui_contacts.dat");
                System.out.println("createContactAccount status addressBook otapi.StoreObject:" + status);
            // Set other values here
            }
            break;
        }
    }
    return status;
}
Also used : ContactAcct(org.opentransactions.otapi.ContactAcct) AddressBook(org.opentransactions.otapi.AddressBook) Storable(org.opentransactions.otapi.Storable) Contact(org.opentransactions.otapi.Contact)

Example 7 with Storable

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

the class StorageHelper method addRippleServer.

//Ripple,Loom
public static String addRippleServer(String label, String url, String user, String pwd, String userTextID, String pwdTextID) {
    String serverID = Helpers.generateID();
    WalletData walletData = Helpers.getWalletData();
    if (walletData == null) {
        System.out.println("addRippleServer - walletData returns null");
        return null;
    }
    RippleServer rippleServer = null;
    Storable storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_RIPPLE_SERVER);
    if (storable != null) {
        rippleServer = RippleServer.ot_dynamic_cast(storable);
        if (rippleServer != null) {
            rippleServer.setServer_host(url);
            rippleServer.setRipple_password(pwd);
            rippleServer.setRipple_username(user);
            rippleServer.setNamefield_id(userTextID);
            rippleServer.setPassfield_id(pwdTextID);
            rippleServer.setGui_label(label);
            rippleServer.setServer_id(serverID);
            rippleServer.setServer_type("Ripple");
            boolean status = walletData.AddRippleServer(rippleServer);
            System.out.println("status walletData.AddRippleServer:" + status);
            status = otapi.StoreObject(walletData, "moneychanger", "gui_wallet.dat");
            System.out.println("status otapi.StoreObject:" + status);
            System.out.println("addRippleServer - serverID:" + serverID);
        }
    }
    return serverID;
}
Also used : RippleServer(org.opentransactions.otapi.RippleServer) WalletData(org.opentransactions.otapi.WalletData) Storable(org.opentransactions.otapi.Storable)

Example 8 with Storable

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

the class StorageHelper method addBitcoinServer.

//Other Tab
public static String addBitcoinServer(String label, String host, String user, String pwd, String port) {
    String serverID = Helpers.generateID();
    WalletData walletData = Helpers.getWalletData();
    if (walletData == null) {
        System.out.println("addBitcoinServer - walletData returns null");
        return null;
    }
    BitcoinServer btcServer = null;
    Storable storable = otapi.CreateObject(StoredObjectType.STORED_OBJ_BITCOIN_SERVER);
    if (storable != null) {
        btcServer = BitcoinServer.ot_dynamic_cast(storable);
        if (btcServer != null) {
            btcServer.setServer_host(host);
            btcServer.setBitcoin_password(pwd);
            btcServer.setBitcoin_username(user);
            btcServer.setServer_port(port);
            btcServer.setGui_label(label);
            btcServer.setServer_id(serverID);
            btcServer.setServer_type("Bitcoin");
            boolean status = walletData.AddBitcoinServer(btcServer);
            System.out.println("status walletData.AddBitcoinServer:" + status);
            status = otapi.StoreObject(walletData, "moneychanger", "gui_wallet.dat");
            System.out.println("status otapi.StoreObject:" + status);
            System.out.println("addBitcoinServer - serverID:" + serverID);
        }
    }
    return serverID;
}
Also used : BitcoinServer(org.opentransactions.otapi.BitcoinServer) WalletData(org.opentransactions.otapi.WalletData) Storable(org.opentransactions.otapi.Storable)

Example 9 with Storable

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

the class Load method SetupPasswordImage.

public boolean SetupPasswordImage(IPasswordImage passwordImage) throws LoadingOpenTransactionsFailure {
    if (!isInitialized) {
        throw new LoadingOpenTransactionsFailure(LoadErrorType.OTAPI_NOT_INSTIGATED, "Is Not Initialized");
    }
    if (isPasswordImageSet) {
        throw new LoadingOpenTransactionsFailure(LoadErrorType.PASSWORD_IMAGE_ALREADY_SET, "Password Image Already Set!");
    }
    String imagePath = "";
    boolean bHaveImage = false;
    // First Lets Check if we already have a password image. (we don't need annother one)
    if (otapi.Exists("moneychanger", "settings.dat")) {
        Storable storable = null;
        StringMap stringMap = null;
        storable = otapi.QueryObject(StoredObjectType.STORED_OBJ_STRING_MAP, "moneychanger", "settings.dat");
        if (null != storable) {
            stringMap = StringMap.ot_dynamic_cast(storable);
            imagePath = stringMap.GetValue("ImagePath");
            File f = new File(imagePath);
            if (f.exists()) {
                // Good we have a password Image
                bHaveImage = true;
            }
        }
    }
    // We don't have an image... lets get it from the user, then save it.
    if (!bHaveImage) {
        for (; ; ) {
            imagePath = passwordImage.GetPasswordImageFromUser("passwordImage");
            if (passwordImage.GetIfUserCancelled()) {
                bHaveImage = false;
                break;
            }
            File f = new File(imagePath);
            if (f.exists()) {
                bHaveImage = true;
                // Good we have a password Image
                break;
            }
        }
        if (!bHaveImage) {
            return false;
        }
        // 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);
            System.out.println("stringMap:" + stringMap);
            if (stringMap != null) {
                //stringMap.SetValue("ImagePath", "~/.ot/default.gif");
                stringMap.SetValue("ImagePath", imagePath);
                bHaveImage = otapi.StoreObject(stringMap, "moneychanger", "settings.dat");
            }
        }
    }
    if (bHaveImage) {
        passwordImage.SetPasswordImage(imagePath);
    } else {
        throw new LoadingOpenTransactionsFailure(LoadErrorType.PASSWORD_IMAGE_FAILED_TO_SET, "Password image not Set!");
    }
    isPasswordImageSet = true;
    return true;
}
Also used : StringMap(org.opentransactions.otapi.StringMap) Storable(org.opentransactions.otapi.Storable) File(java.io.File)

Example 10 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)

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