Search in sources :

Example 6 with OTAPI_Func

use of com.moneychanger.core.util.OTAPI_Func in project otapij by FellowTraveler.

the class OpenTransactionAccount method createAccount.

@Override
public boolean createAccount() {
    boolean bSuccess = false;
    System.out.println("IN createAccount serverID:" + serverID + " nymID: " + nymID + " assetID:" + assetID);
    try {
        //
        if (!otapiJNI.OTAPI_Basic_IsNym_RegisteredAtServer(nymID, serverID)) {
            OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.CREATE_USER_ACCT, serverID, nymID);
            String strResponse = OTAPI_Func.SendRequest(theRequest, "CREATE_USER_ACCT");
            if (!Utility.VerifyStringVal(strResponse)) {
                System.out.println("IN createAccount: OTAPI_Func.SendRequest(() failed. (I give up.) ");
                return false;
            }
            // need to sync it for the first time, in order to do any other messages.
            if (Helpers.getRequestNumber(serverID, nymID) < 1) {
                System.out.println("In createAccount: Failure to call getRequestNumber() after supposedly creating user acct at server.");
            //return false; // commenting this out, so for moa7 types with bad connections, even if this call fails, it'll go ahead and try the next one, and when THAT fails it does another getRequestNumber followed by a retry. So we have plenty of chances to succeed here...
            }
        }
        // -----------------------------------------------
        // Okay the Nym is definitely registered at the server, so let's 
        // create the asset account...
        //
        bSuccess = createAssetAccount(serverID, nymID, assetID);
        if (bSuccess) {
            System.out.println("In createAccount: Success");
        } else {
            System.out.println("In createAccount: Failure");
        }
    } catch (Exception e) {
        //          e.printStackTrace();
        System.out.println("In Exception");
        return false;
    }
    return bSuccess;
}
Also used : OTAPI_Func(com.moneychanger.core.util.OTAPI_Func)

Example 7 with OTAPI_Func

use of com.moneychanger.core.util.OTAPI_Func in project otapij by FellowTraveler.

the class OpenTransactionAccount method withdrawCash.

public boolean withdrawCash(String serverID, String nymID, String accountID, String amount) {
    String serverResponseMessage = null;
    System.out.println("In withdrawCash serverID:" + serverID + " nymID:" + nymID + " acount ID:" + accountID);
    String assetID = otapiJNI.OTAPI_Basic_GetAccountWallet_AssetTypeID(accountID);
    // ---------------------------------------- 
    // Make sure we have the proper asset contract for the withdrawal.
    //
    String assetContract = otapiJNI.OTAPI_Basic_LoadAssetContract(assetID);
    if (!Utility.VerifyStringVal(assetContract)) {
        OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.GET_CONTRACT, serverID, nymID, assetID);
        String strResponse = OTAPI_Func.SendRequest(theRequest, "GET_CONTRACT");
        if (!Utility.VerifyStringVal(strResponse)) {
            System.out.println("IN withdrawCash: OTAPI_Func.SendRequest(GET_CONTRACT) failed. (I give up.) (Unable to find asset contract.)");
            return false;
        }
        // ----------------------------------------
        assetContract = otapiJNI.OTAPI_Basic_LoadAssetContract(assetID);
        if (!Utility.VerifyStringVal(assetContract)) {
            System.out.println("OT_API_LoadAssetContract returned null even after OT_API_getContract (Unable to find asset contract.)");
            return false;
        }
    }
    // ---------------------------------------------------------
    // Download the public mintfile if it's not there, or if it's expired.
    // Also load it up into memory as a string (just to make sure it works.)
    // Then we can actually send the withdrawal transaction request. (Until
    // then, why bother?)
    //
    String mintFile;
    // expired or missing.
    if (true != otapiJNI.OTAPI_Basic_Mint_IsStillGood(serverID, assetID)) {
        // ----------------------------------------
        OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.GET_MINT, serverID, nymID, assetID);
        String strResponse = OTAPI_Func.SendRequest(theRequest, "GET_MINT");
        if (!Utility.VerifyStringVal(strResponse)) {
            System.out.println("IN withdrawCash: OTAPI_Func.SendRequest(GET_MINT) failed. (I give up.) (Unable to get mint.)");
            return false;
        }
        // ----------------------------------------
        mintFile = otapiJNI.OTAPI_Basic_LoadMint(serverID, assetID);
        if (!Utility.VerifyStringVal(mintFile)) {
            System.out.println("OT_API_LoadMint returned null even after OT_API_getMint (I give up.) (Unable to find mint.)");
            return false;
        }
    } else // current mint IS available already on local storage (and not expired.)
    {
        mintFile = otapiJNI.OTAPI_Basic_LoadMint(serverID, assetID);
        if (!Utility.VerifyStringVal(mintFile)) {
            System.out.println("OT_API_LoadMint returned null even after successful OT_API_Mint_IsStillGood (I give up.) (Unable to find mint.)");
            return false;
        }
    }
    // ---------------------------------------------------
    // By this point, the mintfile is DEFINITELY good (available, not null, 
    // not expired, and loaded up.) Now we know for a fact that when the API
    // call is made to withdraw cash, that it will find the mint properly.
    //
    OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.WITHDRAW_CASH, serverID, nymID, accountID, amount);
    // <========================
    String strResponse = OTAPI_Func.SendTransaction(theRequest, "WITHDRAW_CASH");
    if (!Utility.VerifyStringVal(strResponse)) {
        System.out.println("OTAPI_Func.SendTransaction() failed, in withdrawCash.");
        return false;
    }
    return true;
}
Also used : OTAPI_Func(com.moneychanger.core.util.OTAPI_Func)

Example 8 with OTAPI_Func

use of com.moneychanger.core.util.OTAPI_Func in project otapij by FellowTraveler.

the class OpenTransactionAccount method exchangeBasket.

public boolean exchangeBasket(String assetID, String serverID, String nymID, String basket, boolean inXchange, int memberCount, String accountID) {
    String IN_FUNCTION = new String("exchangeBasket");
    System.out.println("In " + IN_FUNCTION + " serverID:" + serverID + " accountID:" + accountID + " nymID:" + nymID + " assetID:" + assetID + " basket:" + basket + " inXchange is " + inXchange + " memberCount:" + memberCount);
    // ----------------------------------------
    OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.EXCHANGE_BASKET, serverID, nymID, assetID, basket, accountID, inXchange, (memberCount + 2));
    String strResponse = OTAPI_Func.SendTransaction(theRequest, "EXCHANGE_BASKET");
    if (!Utility.VerifyStringVal(strResponse)) {
        System.out.println("IN exchangeBasket: OTAPI_Func.SendTransaction(() failed. (I give up.) ");
        return false;
    }
    return true;
}
Also used : OTAPI_Func(com.moneychanger.core.util.OTAPI_Func)

Example 9 with OTAPI_Func

use of com.moneychanger.core.util.OTAPI_Func in project otapij by FellowTraveler.

the class AddBasketDialog method jButton1ActionPerformed.

//GEN-LAST:event_jComboBox6ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    //GEN-FIRST:event_jButton1ActionPerformed
    int minTransferAmt = 0;
    int nbrSubCurrency = 0;
    try {
        minTransferAmt = Integer.parseInt(jTextField1.getText());
    } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
        JOptionPane.showMessageDialog(null, "Please enter positive integer for minimum transfer amount", "Min Transfer Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (minTransferAmt < 1) {
        JOptionPane.showMessageDialog(null, "Please enter positive integer for minimum transfer amount", "Min Transfer Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    try {
        nbrSubCurrency = Integer.parseInt(jTextField2.getText());
    } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
        JOptionPane.showMessageDialog(null, "Please enter positive integer for sub currencies", "Sub currency Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    if (nbrSubCurrency < 2) {
        JOptionPane.showMessageDialog(null, "Minimum value for sub currencies is 2", "Sub currency Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    String nymID = "ALL";
    if (nymRegisteredMap != null && nymRegisteredMap.size() > 0 && jComboBox6.getSelectedIndex() > -1) {
        nymID = ((String[]) nymRegisteredMap.get((Integer) jComboBox6.getSelectedIndex()))[1];
    }
    System.out.println("nymID:" + nymID);
    String basket = otapiJNI.OTAPI_Basic_GenerateBasketCreation(nymID, jTextField1.getText());
    System.out.println("basketID:" + basket);
    if (Basket.getAssetList(serverID, nymID, Helpers.getBasketExistingAssets()).size() < nbrSubCurrency) {
        JOptionPane.showMessageDialog(null, "Sorry, you do not have enough assets as number of sub currencies", "Sub currency Error", JOptionPane.ERROR_MESSAGE);
        return;
    }
    for (int i = 0; i < nbrSubCurrency; i++) {
        System.out.println("Start");
        new SubCurrencyDetailDialog(null, true, serverID, nymID).setVisible(true);
        if (Helpers.getCancelBasket()) {
            break;
        }
        basket = otapiJNI.OTAPI_Basic_AddBasketCreationItem(nymID, basket, Helpers.getSubCurrency(), Helpers.getMinTransfer());
        System.out.println("End");
    }
    Helpers.clearBasketExistingAssets();
    if (!Helpers.getCancelBasket()) {
        OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.ISSUE_BASKET, serverID, nymID, basket);
        String strResponse = OTAPI_Func.SendRequest(theRequest, "ISSUE_BASKET");
        System.out.println("strResponse:" + strResponse);
        if (!Utility.VerifyStringVal(strResponse)) {
            JOptionPane.showMessageDialog(null, "Basket cannot be issued", "Issue basket Error", JOptionPane.ERROR_MESSAGE);
        } else {
            String assetTypeID = otapiJNI.OTAPI_Basic_Message_GetNewAssetTypeID(strResponse);
            System.out.println("New assetTypeID:" + assetTypeID);
            Basket.loadAsset(assetTypeID, nymID, serverID);
            JOptionPane.showMessageDialog(null, "Basket issued successfully", "Issue basket success", JOptionPane.INFORMATION_MESSAGE);
            MainPage.setAssets(serverID, assetTypeID);
        }
    } else {
        JOptionPane.showMessageDialog(null, "Issue of basket cancelled", "Issue basket", JOptionPane.INFORMATION_MESSAGE);
        Helpers.setCancelBasket(false);
    }
    this.dispose();
}
Also used : OTAPI_Func(com.moneychanger.core.util.OTAPI_Func)

Example 10 with OTAPI_Func

use of com.moneychanger.core.util.OTAPI_Func in project otapij by FellowTraveler.

the class Basket method loadAsset.

public static void loadAsset(String assetTypeID, String nymID, String serverID) {
    if (!Utility.VerifyStringVal(otapiJNI.OTAPI_Basic_LoadAssetContract(assetTypeID))) {
        System.out.println("IN getAssetTypeName, OT_API_LoadAssetContract is null");
        // ----------------------------------------
        OTAPI_Func theRequest = new OTAPI_Func(OTAPI_Func.FT.GET_CONTRACT, serverID, nymID, assetTypeID);
        String strResponse = OTAPI_Func.SendRequest(theRequest, "GET_CONTRACT");
        if (!Utility.VerifyStringVal(strResponse)) {
            System.out.println("IN getAssetTypeName: OTAPI_Func.SendRequest(() failed. (I give up.) ");
        }
    }
}
Also used : OTAPI_Func(com.moneychanger.core.util.OTAPI_Func)

Aggregations

OTAPI_Func (com.moneychanger.core.util.OTAPI_Func)30 HashMap (java.util.HashMap)3 Map (java.util.Map)3 MarketData (org.opentransactions.otapi.MarketData)3 MarketList (org.opentransactions.otapi.MarketList)3 MarketTicker (com.moneychanger.core.dataobjects.MarketTicker)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 OfferDataNym (org.opentransactions.otapi.OfferDataNym)2 OfferListNym (org.opentransactions.otapi.OfferListNym)2 MarketDetails (com.moneychanger.core.dataobjects.MarketDetails)1 Date (java.util.Date)1 AskData (org.opentransactions.otapi.AskData)1 BidData (org.opentransactions.otapi.BidData)1 OfferListMarket (org.opentransactions.otapi.OfferListMarket)1 Storable (org.opentransactions.otapi.Storable)1 StringMap (org.opentransactions.otapi.StringMap)1 TradeDataMarket (org.opentransactions.otapi.TradeDataMarket)1 TradeListMarket (org.opentransactions.otapi.TradeListMarket)1 Utility (org.opentransactions.otjavalib.util.Utility)1