Пример #1
0
std::string standardtxout(bool bHelp, params_t& params)
{
    if (bHelp || params.size() < 2 || params.size() > 3) {
        return "standardtxout <address> <value> [options] - creates a standard transaction output. Use option -h for serialized hex.";
    }

    bool bHex = false;
    if (params.size() == 3) {
        if (params[2] == "-h") {
            bHex = true;
        }
        else {
            throw std::runtime_error(std::string("Invalid option: ") + params[2]);
        }
    }

    StandardTxOut txOut;
    txOut.set(params[0], strtoull(params[1].c_str(), NULL, 10));

    if (bHex) {
        return txOut.getSerialized().getHex();
    }
    else {
        return txOut.toJson();
    }
}
Пример #2
0
// for each key/value in params_one, set params_two[key] = value
void merge_params(params_t& params_one, params_t& params_two) {
    map<string,string>::iterator iter;
    for(iter = params_one.begin(); iter != params_one.end(); iter++) {
        string param_key(iter->first);
        params_two[param_key] = params_one[param_key];
    }
};
Пример #3
0
std::string signtransaction(bool bHelp, params_t& params)
{
    if (bHelp || params.size() < 6) {
        return "signtransaction <outhash> <outindex> <redeemscript> <toaddress> <value> <privkey1> [<privkey2> <privkey3> ...] - creates and signs a transaction claiming a multisignature input.";
    }

    uchar_vector outHash = params[0];
    uint outIndex = strtoul(params[1].c_str(), NULL, 10);
    uchar_vector redeemScript = params[2];
    std::string toAddress = params[3];
    uint64_t value = strtoull(params[4].c_str(), NULL, 10);

    std::vector<std::string> privKeys;
    for (uint i = 5; i < params.size(); i++) {
        privKeys.push_back(params[i]);
    }

    StandardTxOut txOut;
    txOut.set(toAddress, value);

    MultiSigRedeemScript multiSig;
    multiSig.parseRedeemScript(redeemScript);

    P2SHTxIn txIn(outHash, outIndex, multiSig.getRedeemScript());
    txIn.setScriptSig(SCRIPT_SIG_SIGN);

    Transaction tx;
    tx.addOutput(txOut);
    tx.addInput(txIn);
    uchar_vector hashToSign = tx.getHashWithAppendedCode(1); // SIGHASH_ALL

    // TODO: make sure to wipe all key data if there's any failure
    CoinKey key;
    for (uint i = 0; i < privKeys.size(); i++) {
        if (!key.setWalletImport(privKeys[i])) {
            std::stringstream ss;
            ss << "Private key " << i+1 << " is invalid.";
            throw std::runtime_error(ss.str());
        }

        uchar_vector sig;
        if (!key.sign(hashToSign, sig)) {
            std::stringstream ss;
            ss << "Error signing with key " << i+1 << ".";
            throw std::runtime_error(ss.str());
        }
        txIn.addSig(uchar_vector(), sig);
    }

    if (privKeys.size() < multiSig.getMinSigs()) {
        txIn.setScriptSig(SCRIPT_SIG_EDIT);
    }
    else {
        txIn.setScriptSig(SCRIPT_SIG_BROADCAST);
    }
    tx.clearInputs();
    tx.addInput(txIn);
    return tx.getSerialized().getHex();
}
Пример #4
0
void get_extension_params(params_t& extparams, params_t& params) {
    map<string,string>::iterator iter;
    extparams.reset_fields();
    for(iter = params.begin(); iter != params.end(); iter++) {
        string param_key(iter->first);
        vector<string> parts = explode(param_key, ".");
        // if there is more than one "." in the param name then we're
        // dealing with an extension parameter
        if(parts.size() > 2)
            extparams[param_key] = params[param_key];
    }
};
Пример #5
0
void remove_openid_vars(params_t& params) {
    map<string,string>::iterator iter, iter_next;
    for(iter = params.begin(); iter != params.end(); ) {
        iter_next = iter;
        ++iter_next;
        string param_key(iter->first);
        // if starts with openid. or modauthopenid. (for the nonce) or openid_identifier (the login) remove it
        if((param_key.substr(0, 7) == "openid." || param_key.substr(0, 14) == "modauthopenid." || param_key == "openid_identifier")) {
            params.erase(iter); // invalidates iter, but its successor iter_next is still valid
        }
        iter = iter_next;
    }
};
Пример #6
0
  void remove_openid_vars(params_t& params) {
    map<string,string>::iterator iter;
    for(iter = params.begin(); iter != params.end(); iter++) {
      string param_key(iter->first);
      // if starts with openid. or modauthopenid. (for the nonce) or openid_identifier (the login) remove it
      if((param_key.substr(0, 7) == "openid." || param_key.substr(0, 14) == "modauthopenid." || param_key == "openid_identifier")) {
        params.erase(param_key);
        // stupid map iterator screws up if we just continue the iteration... 
	// so recursion to the rescue - we'll delete them one at a time    
	remove_openid_vars(params);
        return;
      }
    }
  };
Пример #7
0
std::string createtransaction(bool bHelp, params_t& params)
{
    if (bHelp || params.size() != 5) {
        return "createtransaction <outhash> <outindex> <redeemscript> <toaddress> <value> - creates a transaction claiming a multisignature input.";
    }

    uchar_vector outHash = params[0];
    uint outIndex = strtoul(params[1].c_str(), NULL, 10);
    uchar_vector redeemScript = params[2];
    std::string toAddress = params[3];
    uint64_t value = strtoull(params[4].c_str(), NULL, 10);

    StandardTxOut txOut;
    txOut.set(toAddress, value);

    MultiSigRedeemScript multiSig;
    multiSig.parseRedeemScript(redeemScript);

    P2SHTxIn txIn(outHash, outIndex, multiSig.getRedeemScript());
    txIn.setScriptSig(SCRIPT_SIG_SIGN);

    Transaction tx;
    tx.addOutput(txOut);
    tx.addInput(txIn);
    uchar_vector hashToSign = tx.getHashWithAppendedCode(1); // SIGHASH_ALL

    for (uint i = 0; i < multiSig.getPubKeyCount(); i++) {
        txIn.addSig(uchar_vector(), uchar_vector(), SIGHASH_ALREADYADDED);
    }

    txIn.setScriptSig(SCRIPT_SIG_EDIT);
    tx.clearInputs();
    tx.addInput(txIn);
    return tx.getSerialized().getHex();
}
Пример #8
0
    void
    execute(xmlrpc_c::paramList const& paramList,
            xmlrpc_c::value *   const  retvalP) {
#ifdef WITH_DLIB
        const params_t params = paramList.getStruct(0);
        params_t::const_iterator si = params.find("model_name");
        if (si == params.end()) {
            throw xmlrpc_c::fault(
                "Missing name of model to be optimized (e.g. PhraseDictionaryMultiModelCounts0)",
                xmlrpc_c::fault::CODE_PARSE);
        }
        const string model_name = xmlrpc_c::value_string(si->second);
        PhraseDictionaryMultiModel* pdmm = (PhraseDictionaryMultiModel*) FindPhraseDictionary(model_name);

        si = params.find("phrase_pairs");
        if (si == params.end()) {
            throw xmlrpc_c::fault(
                "Missing list of phrase pairs",
                xmlrpc_c::fault::CODE_PARSE);
        }

        vector<pair<string, string> > phrase_pairs;

        xmlrpc_c::value_array phrase_pairs_array = xmlrpc_c::value_array(si->second);
        vector<xmlrpc_c::value> phrasePairValueVector(phrase_pairs_array.vectorValueValue());
        for (size_t i=0; i < phrasePairValueVector.size(); i++) {
            xmlrpc_c::value_array phrasePairArray = xmlrpc_c::value_array(phrasePairValueVector[i]);
            vector<xmlrpc_c::value> phrasePair(phrasePairArray.vectorValueValue());
            string L1 = xmlrpc_c::value_string(phrasePair[0]);
            string L2 = xmlrpc_c::value_string(phrasePair[1]);
            phrase_pairs.push_back(make_pair(L1,L2));
        }

        vector<float> weight_vector;
        weight_vector = pdmm->MinimizePerplexity(phrase_pairs);

        vector<xmlrpc_c::value> weight_vector_ret;
        for (size_t i=0; i < weight_vector.size(); i++) {
            weight_vector_ret.push_back(xmlrpc_c::value_double(weight_vector[i]));
        }
        *retvalP = xmlrpc_c::value_array(weight_vector_ret);
#else
        string errmsg = "Error: Perplexity minimization requires dlib (compilation option --with-dlib)";
        cerr << errmsg << endl;
        *retvalP = xmlrpc_c::value_string(errmsg);
#endif
    }
Пример #9
0
 //! Constructor.
 agent_queue_t(
     //! Dispatcher queue to work with.
     dispatcher_queue_t & disp_queue,
     //! Parameters for the queue.
     const params_t & params )
     :	m_disp_queue( disp_queue )
     ,	m_max_demands_at_once( params.query_max_demands_at_once() )
     ,	m_tail( &m_head )
 {}
Пример #10
0
 void AppendParams(params_t& params, const ::std::string& data)
 {
     if( StringIsBlank(data) )
     {
         return;
     }
     ::std::istringstream strm(data);
     T param;
     strm >> param;
     params.push_back(param);
 }
Пример #11
0
 void breakOutParams(const params_t& params) {
     params_t::const_iterator si = params.find("source");
     if(si == params.end())
         throw xmlrpc_c::fault("Missing source sentence", xmlrpc_c::fault::CODE_PARSE);
     source_ = xmlrpc_c::value_string(si->second);
     cerr << "source = " << source_ << endl;
     si = params.find("target");
     if(si == params.end())
         throw xmlrpc_c::fault("Missing target sentence", xmlrpc_c::fault::CODE_PARSE);
     target_ = xmlrpc_c::value_string(si->second);
     cerr << "target = " << target_ << endl;
     si = params.find("alignment");
     if(si == params.end())
         throw xmlrpc_c::fault("Missing alignment", xmlrpc_c::fault::CODE_PARSE);
     alignment_ = xmlrpc_c::value_string(si->second);
     cerr << "alignment = " << alignment_ << endl;
     si = params.find("bounded");
     bounded_ = (si != params.end());
     si = params.find("updateORLM");
     add2ORLM_ = (si != params.end());
 }
Пример #12
0
 bool isValidParamCount(const params_t& params) const
 {
     std::size_t nParams = params.size();
     std::size_t min = reqparams_.size();
     return nParams >= min && (ellipsescount_ || nParams <= min + optparams_.size());
 }
Пример #13
0
    void
    execute(xmlrpc_c::paramList const& paramList,
            xmlrpc_c::value *   const  retvalP) {

        const params_t params = paramList.getStruct(0);
        paramList.verifyEnd(1);
        params_t::const_iterator si = params.find("text");
        if (si == params.end()) {
            throw xmlrpc_c::fault(
                "Missing source text",
                xmlrpc_c::fault::CODE_PARSE);
        }
        const string source(
            (xmlrpc_c::value_string(si->second)));

        cerr << "Input: " << source << endl;
        si = params.find("align");
        bool addAlignInfo = (si != params.end());
        si = params.find("sg");
        bool addGraphInfo = (si != params.end());
        si = params.find("topt");
        bool addTopts = (si != params.end());
        si = params.find("report-all-factors");
        bool reportAllFactors = (si != params.end());
        si = params.find("nbest");
        int nbest_size = (si == params.end()) ? 0 : int(xmlrpc_c::value_int(si->second));
        si = params.find("nbest-distinct");
        bool nbest_distinct = (si != params.end());

        vector<float> multiModelWeights;
        si = params.find("lambda");
        if (si != params.end()) {
            xmlrpc_c::value_array multiModelArray = xmlrpc_c::value_array(si->second);
            vector<xmlrpc_c::value> multiModelValueVector(multiModelArray.vectorValueValue());
            for (size_t i=0; i < multiModelValueVector.size(); i++) {
                multiModelWeights.push_back(xmlrpc_c::value_double(multiModelValueVector[i]));
            }
        }

        const StaticData &staticData = StaticData::Instance();

        if (addGraphInfo) {
            (const_cast<StaticData&>(staticData)).SetOutputSearchGraph(true);
        }

        if (multiModelWeights.size() > 0) {
            PhraseDictionaryMultiModel* pdmm = (PhraseDictionaryMultiModel*) staticData.GetPhraseDictionaries()[0]; //TODO: only works if multimodel is first phrase table
            pdmm->SetTemporaryMultiModelWeightsVector(multiModelWeights);
        }

        stringstream out, graphInfo, transCollOpts;
        map<string, xmlrpc_c::value> retData;

        if (staticData.IsChart()) {
            TreeInput tinput;
            const vector<FactorType> &inputFactorOrder =
                staticData.GetInputFactorOrder();
            stringstream in(source + "\n");
            tinput.Read(in,inputFactorOrder);
            ChartManager manager(tinput);
            manager.ProcessSentence();
            const ChartHypothesis *hypo = manager.GetBestHypothesis();
            outputChartHypo(out,hypo);
        } else {
            Sentence sentence;
            const vector<FactorType> &inputFactorOrder =
                staticData.GetInputFactorOrder();
            stringstream in(source + "\n");
            sentence.Read(in,inputFactorOrder);
            size_t lineNumber = 0; // TODO: Include sentence request number here?
            Manager manager(lineNumber, sentence, staticData.GetSearchAlgorithm());
            manager.ProcessSentence();
            const Hypothesis* hypo = manager.GetBestHypothesis();

            vector<xmlrpc_c::value> alignInfo;
            outputHypo(out,hypo,addAlignInfo,alignInfo,reportAllFactors);
            if (addAlignInfo) {
                retData.insert(pair<string, xmlrpc_c::value>("align", xmlrpc_c::value_array(alignInfo)));
            }

            if(addGraphInfo) {
                insertGraphInfo(manager,retData);
                (const_cast<StaticData&>(staticData)).SetOutputSearchGraph(false);
            }
            if (addTopts) {
                insertTranslationOptions(manager,retData);
            }
            if (nbest_size>0) {
                outputNBest(manager, retData, nbest_size, nbest_distinct, reportAllFactors);
            }
        }
        pair<string, xmlrpc_c::value>
        text("text", xmlrpc_c::value_string(out.str()));
        retData.insert(text);
        cerr << "Output: " << out.str() << endl;
        *retvalP = xmlrpc_c::value_struct(retData);
    }
Пример #14
0
 static bool
 is_individual_fifo( const params_t & params )
 {
     return fifo_t::individual == params.query_fifo();
 }