Ejemplo n.º 1
1
    void EtherIPC::sendTransaction(const QString& from, const QString& to, const QString& valStr, const QString& gas) {
        QJsonArray params;
        const QString valHex = Helpers::toHexWeiStr(valStr);
        EtherLog::logMsg(QString("Trans Value: ") + valStr + QString(" HexValue: ") + valHex);

        QJsonObject p;
        p["from"] = from;
        p["to"] = to;
        p["value"] = valHex;
        if ( !gas.isEmpty() ) {
            const QString gasHex = Helpers::decStrToHexStr(gas);
            p["gas"] = gasHex;
        }

        params.append(p);

        if ( !queueRequest(RequestIPC(SendTransaction, "eth_sendTransaction", params)) ) {
            return bail(true); // softbail
        }
    }
Ejemplo n.º 2
0
    void EtherIPC::sendTransaction(const QString& from, const QString& to, const QString& valStr, const QString& password,
                                   const QString& gas, const QString& gasPrice, const QString& data) {
        QJsonArray params;
        const QString valHex = Helpers::toHexWeiStr(valStr);
        QJsonObject p;
        p["from"] = from;
        p["value"] = valHex;
        if ( !to.isEmpty() ) {
            p["to"] = to;
        }
        if ( !gas.isEmpty() ) {
            const QString gasHex = Helpers::decStrToHexStr(gas);
            p["gas"] = gasHex;
        }
        if ( !gasPrice.isEmpty() ) {
            const QString gasPriceHex = Helpers::toHexWeiStr(gasPrice);
            p["gasPrice"] = gasPriceHex;
            EtherLog::logMsg(QString("Trans gasPrice: ") + gasPrice + QString(" HexValue: ") + gasPriceHex);
        }
        if ( !data.isEmpty() ) {
            p["data"] = data;
        }

        params.append(p);
        params.append(password);

        if ( !queueRequest(RequestIPC(SendTransaction, "personal_signAndSendTransaction", params)) ) {
            return bail(true); // softbail
        }
    }
Ejemplo n.º 3
0
    void EtherIPC::estimateGas(const QString& from, const QString& to, const QString& valStr,
                                   const QString& gas, const QString& gasPrice, const QString& data) {
        const QString valHex = Helpers::toHexWeiStr(valStr);
        QJsonArray params;
        QJsonObject p;
        p["from"] = from;
        p["value"] = valHex;
        if ( !to.isEmpty() ) {
            p["to"] = to;
        }
        if ( !gas.isEmpty() ) {
            const QString gasHex = Helpers::decStrToHexStr(gas);
            p["gas"] = gasHex;
        }
        if ( !gasPrice.isEmpty() ) {
            const QString gasPriceHex = Helpers::toHexWeiStr(gasPrice);
            p["gasPrice"] = gasPriceHex;
        }
        if ( !data.isEmpty() ) {
            p["data"] = data;
        }

        params.append(p);
        if ( !queueRequest(RequestIPC(EstimateGas, "eth_estimateGas", params)) ) {
            return bail();
        }
    }
Ejemplo n.º 4
0
    bool EtherIPC::closeApp() {
        fClosingApp = true;
        fTimer.stop();

        if ( fSocket.state() == QLocalSocket::UnconnectedState ) {
            return true;
        }

        if ( fSocket.state() == QLocalSocket::ConnectedState && getBusy() ) { // wait for operation first if we're still connected
            return false;
        }

        if ( fSocket.state() == QLocalSocket::ConnectedState && fFilterID >= 0 ) { // remove filter if still connected
            uninstallFilter();
            return false;
        }

        if ( fSocket.state() != QLocalSocket::UnconnectedState ) { // wait for clean disconnect
            fActiveRequest = RequestIPC(Full);
            fSocket.disconnectFromServer();
            return false;
        }

        return true;
    }
Ejemplo n.º 5
0
    //Constructor for the send transcation stuff
    void EtherIPC::sendTransaction(const QString& from, const QString& to, const QString& valStr, const QString& gas, const QString& name, const QString& prodId, const QString& sNum, const QString& item, const QString& desc){
        QJsonArray params;
        const QString valHex = Helpers::toHexWeiStr(valStr);
        EtherLog::logMsg(QString("Trans Value: ") + valStr + QString(" HexValue: ") + valHex);

        QJsonObject p;
        p["from"] = from;
        p["to"] = to;
        p["value"] = valHex;
        p["name"] = name;
       //Addedums for the new fields
        p["prodId"]=prodId;
        p["sNum"]=sNum;
        p["item"] = item;
        p["desc"] = desc;
        if ( !gas.isEmpty() ) {
            const QString gasHex = Helpers::decStrToHexStr(gas);
            p["gas"] = gasHex;
        }

        params.append(p);

        if ( !queueRequest(RequestIPC(SendTransaction, "eth_sendTransaction", params)) ) {
            return bail(true); // softbail
        }
    }
Ejemplo n.º 6
0
 void EtherIPC::newAccount(const QString& password, int index) {
     QJsonArray params;
     params.append(password);
     if ( !queueRequest(RequestIPC(NewAccount, "personal_newAccount", params, index)) ) {
         return bail();
     }
 }
Ejemplo n.º 7
0
    void EtherIPC::getTransactionByHash(const QString& hash) {
        QJsonArray params;
        params.append(hash);

        if ( !queueRequest(RequestIPC(GetTransactionByHash, "eth_getTransactionByHash", params)) ) {
            return bail();
        }
    }
Ejemplo n.º 8
0
 void EtherIPC::deleteAccount(const QString& hash, const QString& password, int index) {
     QJsonArray params;
     params.append(hash);
     params.append(password);        
     if ( !queueRequest(RequestIPC(DeleteAccount, "personal_deleteAccount", params, index)) ) {
         return bail();
     }
 }
Ejemplo n.º 9
0
    void EtherIPC::getBlockByHash(const QString& hash) {
        QJsonArray params;
        params.append(hash);
        params.append(true); // get transaction bodies

        if ( !queueRequest(RequestIPC(GetBlock, "eth_getBlockByHash", params)) ) {
            return bail();
        }
    }
Ejemplo n.º 10
0
    void EtherIPC::getBlockByNumber(quint64 blockNum) {
        QJsonArray params;
        params.append(Helpers::toHexStr(blockNum));
        params.append(true); // get transaction bodies

        if ( !queueRequest(RequestIPC(GetBlock, "eth_getBlockByNumber", params)) ) {
            return bail();
        }
    }
Ejemplo n.º 11
0
    void EtherIPC::getFilterChanges(int filterID) {
        QJsonArray params;
        BigInt::Vin vinVal(filterID);
        QString strHex = QString(vinVal.toStr0xHex().data());
        params.append(strHex);

        if ( !queueRequest(RequestIPC(NonVisual, GetFilterChanges, "eth_getFilterChanges", params, filterID)) ) {
            return bail();
        }
    }
Ejemplo n.º 12
0
    void EtherIPC::uninstallFilter() {
        QJsonArray params;
        BigInt::Vin vinVal(fFilterID);
        QString strHex = QString(vinVal.toStr0xHex().data());
        params.append(strHex);

        if ( !queueRequest(RequestIPC(UninstallFilter, "eth_uninstallFilter", params)) ) {
            return bail();
        }
    }
Ejemplo n.º 13
0
 void EtherIPC::done() {
     fActiveRequest = RequestIPC(None);
     if ( !fRequestQueue.isEmpty() ) {
         const RequestIPC request = fRequestQueue.first();
         fRequestQueue.removeFirst();
         writeRequest(request);
     } else {
         emit busyChanged(getBusy());
     }
 }
Ejemplo n.º 14
0
    void EtherIPC::newBlockFilter() {
        if ( !fBlockFilterID.isEmpty() ) {
            setError("Filter already set");
            return bail(true);
        }

        if ( !queueRequest(RequestIPC(NewBlockFilter, "eth_newBlockFilter")) ) {
            return bail();
        }
    }
Ejemplo n.º 15
0
    bool EtherIPC::getTransactionCount(const QString& hash, int index) {
        QJsonArray params;
        params.append(hash);
        params.append(QString("latest"));
        if ( !queueRequest(RequestIPC(GetTransactionCount, "eth_getTransactionCount", params, index)) ) {
            bail();
            return false;
        }

        return true;
    }
Ejemplo n.º 16
0
    void EtherIPC::bail(bool soft) {
        qDebug() << "BAIL[" << soft << "]: " << fError << "\n";

        if ( !soft ) {
            fTimer.stop();
            fRequestQueue.clear();
        }

        fActiveRequest = RequestIPC(None);
        errorOut();
    }
Ejemplo n.º 17
0
    void EtherIPC::newEventFilter(const QStringList& addresses, const QStringList& topics) {
        QJsonArray params;
        QJsonObject o;
        o["address"] = QJsonArray::fromStringList(addresses);
        if ( topics.length() > 0 && topics.at(0).length() > 0 ) {
            o["topics"] = QJsonArray::fromStringList(topics);
        }
        params.append(o);

        if ( !queueRequest(RequestIPC(NewEventFilter, "eth_newFilter", params)) ) {
            return bail();
        }
    }
Ejemplo n.º 18
0
    void EtherIPC::getFilterChanges(const QString& filterID) {
        if ( filterID < 0 ) {
            setError("Filter ID invalid");
            return bail();
        }

        QJsonArray params;
        params.append(filterID);

        if ( !queueRequest(RequestIPC(NonVisual, GetFilterChanges, "eth_getFilterChanges", params)) ) {
            return bail();
        }
    }
Ejemplo n.º 19
0
 void EtherIPC::estimateGas(const QString& from, const QString& to, const QString& value) {
     QJsonArray params;
     QJsonObject o;
     o["to"] = to;
     o["from"] = from;
     o["value"] = Helpers::toHexWeiStr(value);
     o["gas"] = Helpers::toHexStr(90000);
     params.append(o);
     params.append(QString("latest"));
     if ( !queueRequest(RequestIPC(EstimateGas, "eth_estimateGas", params)) ) {
         return bail();
     }
 }
Ejemplo n.º 20
0
    void EtherIPC::unlockAccount(const QString& hash, const QString& password, int duration, int index) {
        QJsonArray params;
        params.append(hash);
        params.append(password);

        BigInt::Vin vinVal(duration);
        QString strHex = QString(vinVal.toStr0xHex().data());
        params.append(strHex);

        if ( !queueRequest(RequestIPC(UnlockAccount, "personal_unlockAccount", params, index)) ) {
            return bail();
        }
    }
Ejemplo n.º 21
0
    void EtherIPC::getLogs(const QStringList& addresses, const QStringList& topics, quint64 fromBlock) {
        QJsonArray params;
        QJsonObject o;
        o["fromBlock"] = fromBlock == 0 ? "latest" : Helpers::toHexStr(fromBlock);
        o["address"] = QJsonArray::fromStringList(addresses);
        if ( topics.length() > 0 && topics.at(0).length() > 0 ) {
            o["topics"] = QJsonArray::fromStringList(topics);
        }
        params.append(o);

        // we can use getFilterChanges as result is the same
        if ( !queueRequest(RequestIPC(GetLogs, "eth_getLogs", params)) ) {
            return bail();
        }
    }
Ejemplo n.º 22
0
    void EtherIPC::uninstallFilter(const QString& filter) {
        if ( filter.isEmpty() ) {
            setError("Filter not set");
            return bail(true);
        }

        //qDebug() << "uninstalling filter: " << fBlockFilterID << "\n";

        QJsonArray params;
        params.append(filter);

        if ( !queueRequest(RequestIPC(UninstallFilter, "eth_uninstallFilter", params)) ) {
            return bail();
        }
    }
Ejemplo n.º 23
0
    void EtherIPC::connectToServer() {
        fActiveRequest = RequestIPC(Full);
        emit busyChanged(getBusy());
        if ( fSocket.state() != QLocalSocket::UnconnectedState ) {
            setError("Already connected");
            return bail();
        }

        fSocket.connectToServer(fPath);
        if ( fConnectAttempts == 0 ) {
            if ( fStarting == 1 ) {
                EtherLog::logMsg("Checking to see if there is an already running geth...");
            } else {
                EtherLog::logMsg("Connecting to IPC socket " + fPath);
            }
        }

        QTimer::singleShot(2000, this, SLOT(waitConnect()));
    }
Ejemplo n.º 24
0
    void EtherIPC::connectToServer(const QString& path) {
        if ( fAborted ) {
            bail();
            return;
        }

        fActiveRequest = RequestIPC(Full);
        emit busyChanged(getBusy());
        fPath = path;
        if ( fSocket.state() != QLocalSocket::UnconnectedState ) {
            setError("Already connected");
            return bail();
        }

        fSocket.connectToServer(path);
        EtherLog::logMsg("Connecting to IPC socket");

        QTimer::singleShot(2000, this, SLOT(connectionTimeout()));
    }
Ejemplo n.º 25
0
    bool EtherIPC::closeApp() {
        EtherLog::logMsg("Closing etherwall");
        fClosingApp = true;
        fTimer.stop();
        emit closingChanged(true);

        if ( fSocket.state() == QLocalSocket::ConnectedState && getBusy() ) { // wait for operation first if we're still connected
            return false;
        }

        if ( fSocket.state() == QLocalSocket::ConnectedState ) {
            bool removed = false;
            if ( !fBlockFilterID.isEmpty() ) { // remove block filter if still connected
                uninstallFilter(fBlockFilterID);
                fBlockFilterID.clear();
                removed = true;
            }

            if ( !fEventFilterID.isEmpty() ) { // remove event filter if still connected
                uninstallFilter(fEventFilterID);
                fEventFilterID.clear();
                removed = true;
            }

            if ( removed ) {
                return false;
            }
        }

        if ( fSocket.state() != QLocalSocket::UnconnectedState ) { // wait for clean disconnect
            fActiveRequest = RequestIPC(Full);
            fSocket.disconnectFromServer();
            return false;
        }

        return killGeth();
    }
Ejemplo n.º 26
0
 void EtherIPC::getPeerCount() {
     if ( !queueRequest(RequestIPC(NonVisual, GetPeerCount, "net_peerCount")) ) {
         return bail();
     }
 }
Ejemplo n.º 27
0
 void EtherIPC::getBlockNumber() {
     if ( !queueRequest(RequestIPC(NonVisual, GetBlockNumber, "eth_blockNumber")) ) {
         return bail();
     }
 }
Ejemplo n.º 28
0
 void EtherIPC::getClientVersion() {
     if ( !queueRequest(RequestIPC(NonVisual, GetClientVersion, "web3_clientVersion")) ) {
         return bail();
     }
 }
Ejemplo n.º 29
0
 void EtherIPC::getGasPrice() {
     if ( !queueRequest(RequestIPC(GetGasPrice, "eth_gasPrice")) ) {
         return bail();
     }
 }
Ejemplo n.º 30
0
 void EtherIPC::newFilter() {
     if ( !queueRequest(RequestIPC(NewFilter, "eth_newBlockFilter")) ) {
         return bail();
     }
 }