Example #1
0
function main($mainmsg)
{
    gio::output(config::$walletMessage);
    $serv = popen("service.ecsh", 'r');
    $net = new Gnet();
    $inerr = 0;
    while (true) {
        if (!$inerr) {
            gio::output();
            foreach ($mainmsg as $k => $v) {
                gio::output("{$k} - {$v}");
            }
            gio::output();
            $msg = "Enter your choice and press enter";
        }
        $inerr = 0;
        $c = gio::input("{$msg}");
        switch ($c) {
            case 1:
                $tid = gio::input("Enter the transaction Id");
                $st = transaction::status($tid);
                if (!$st) {
                    gio::output("Transaction reference '{$tid}' not found");
                } else {
                    $rpt['order id'] = $st['order id'];
                    $rpt['order amount'] = $st['amount'];
                    $rpt['from'] = $st['client'];
                    $rpt['to'] = $st['merchant'];
                    $rpt['transaction time'] = date(config::$timeFormat, $st['acknowledgement']['completed']);
                    $rpt['description'] = $st['description'];
                    $rpt['transaction reference'] = $st['acknowledgement']['id'];
                    $rpt['response code'] = $st['acknowledgement']['status'];
                    $rpt['response message'] = $st['acknowledgement']['message'];
                    $rpt['ecash value tendered'] = $st['acknowledgement']['amount'];
                    $rpt['ecash tendered'] = $st['acknowledgement']['ecashids'];
                    gio::display($rpt);
                    if (gio::confirm("Do you want to save the report to a file")) {
                        $dest = gio::input("Enter full path to the file");
                        gio::display($rpt, $x);
                        if (!gio::saverawfile(join("\r\n", $x), $dest)) {
                            gio::output("Could not save the report to {$dest}");
                        } else {
                            gio::output("Report successfully saved to {$dest}");
                        }
                        unset($x);
                    }
                }
                break;
            case 2:
                $maxallowed = 1000;
                $v = gio::input("What value of eCash do you wish to mine", "integer");
                $n = gio::input("How many eCashes do you wish to mine", "integer");
                $c = mine::countcoins($null);
                unset($null);
                if ($n > $maxallowed || $c + $n > $maxallowed) {
                    $rem = $maxallowed - $c;
                    gio::output("You can not mine above {$maxallowed} eCashes!");
                    gio::output("You can mine {$rem} more eCashes!");
                } else {
                    $res = mine::coins($n, $v);
                    if ($res) {
                        gio::output("You have successfully mined {$n} eCashes.");
                        gio::output("Mining process took " . Tools::arrtostr($res, ", "));
                    } else {
                        gio::output("Mining operation failed!");
                    }
                }
                break;
            case 3:
                $n = mine::countcoins($coins);
                gio::output("A total of {$n} eCash value is available");
                if ($n && gio::confirm("Do you wish to see their Id's")) {
                    foreach ($coins as $val => $ccs) {
                        foreach ($ccs as $i => $coin) {
                            gio::output("Ecash ID: {$i}");
                            foreach ($coin as $id => $c) {
                                if ($id == "token") {
                                    $c = md5($c);
                                }
                                if ($id == "hash") {
                                    $c = sha1($c);
                                }
                                if ($id == "mined") {
                                    $c = date(config::$timeFormat, $c);
                                }
                                gio::output("{$id}=>{$c}");
                            }
                            gio::output();
                        }
                    }
                }
                break;
            case 4:
                $to = gio::input("Enter the wallet address");
                $amt = gio::input("Enter the amount to give");
                $res = account::give($to, $amt);
                break;
            case "x":
                $net->connect(config::$serviceAddress, intval(config::$servicePort));
                $net->send("shutdown");
                if ($serv) {
                    $ret = pclose($serv);
                }
                break 2;
            default:
                $inerr = 1;
                $msg = "Retry";
        }
        if (!$inerr) {
            gio::output("\n\n\n");
        }
    }
    if (isset($ret) && $ret != 0) {
        gio::output("An error occured while exiting...");
    }
    gio::output(config::$exitMessage);
    sleep(3);
}
Example #2
0
 public static function process($msg)
 {
     $status = 1;
     $sender = "";
     $res = "";
     $umsg = GsonCrypt::unseal($msg);
     if (!$umsg) {
         $ex = Gmsg::extract($msg);
         if ($ex && is_array($ex)) {
             $umsg = $msg;
         } else {
             $status = 0;
             $res = "Unable to decode the message";
         }
     }
     if ($umsg) {
         $parts = self::extract($umsg);
         $action = $parts["op"];
         $mess = $parts["msg"];
         $sender = $parts["sender"];
         $recipient = $parts["recipient"];
         if ($recipient && !account::exists($recipient)) {
             $status = 0;
             $res = "The recipient account {$recipient} does not reside here";
             $rply = Gmsg::create(array("status" => $status, "response" => $res));
         } else {
             switch ($action) {
                 case "mrequest":
                     $r = transaction::request($mess['m'], $sender, $mess['k']);
                     $rply = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     break;
                 case "mstatus":
                     $r = transaction::mercorder($mess['m'], $sender, $mess['k']);
                     $rply = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     break;
                 case "statusrequest":
                     $r = transaction::status($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "paymentrequest":
                     $r = transaction::request($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "pullrequests":
                     $r = transaction::pullrequests($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "pullcoins":
                     $r = account::pullcoins($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "clearrequests":
                     $r = transaction::clearrequests($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "notification":
                     $r = transaction::notification($mess, $sender);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "acknowledgement":
                     $r = transaction::acknowledgement($mess, config::$SRA);
                     $m = Gmsg::create(array("status" => $r[0], "response" => $r[1]));
                     $rply = GsonCrypt::sign($m);
                     break;
                 case "deposit":
                     $r = account::deposit($mess, $recipient);
                     if (!$r) {
                         $status = 0;
                         $res = "Deposit failed";
                     } else {
                         $res = "Deposit was successful";
                     }
                     break;
                 case "revokecert":
                     $net = new Gnet();
                     $rply = $net->send("{$mess}", true);
                     $net = null;
                     break;
                 case "signcert":
                     $net = new Gnet();
                     $rply = $net->send("{$mess}", true);
                     $net = null;
                     break;
                 case "register":
                     $k = GsonCrypt::getcert();
                     if (is_readable($k)) {
                         $res = gio::readfile($k);
                         if (!$res) {
                             $status = 0;
                         }
                     }
                     $rply = Gmsg::create(array("status" => $status, "cert" => $res, "name" => config::$accountId, "account" => account::makenew()));
                     break;
                 case "create":
                     $status = gio::savetofile($mess, GsonCrypt::getkey("{$sender}"));
                     $res = $status ? "successful" : "failed";
                     $rply = Gmsg::create(array("status" => $status, "response" => $res));
                     break;
                 case "remove":
                     $res = "";
                     $ret = array("status" => $status, "response" => $res);
                     $rply = self::create($ret);
                     $rply = GsonCrypt::seal("{$rply}", "{$sender}");
                     unlink(GsonCrypt::getkey($sender));
                     break;
                 case "exchangecert":
                     $status = 0;
                     if (!file_exists(GsonCrypt::getcert("{$sender}"))) {
                         $status = gio::saverawfile($mess, GsonCrypt::getcert("{$sender}"));
                     }
                     $k = GsonCrypt::getcert();
                     if ($status && is_readable($k)) {
                         $res = gio::readfile($k);
                         if (!$res) {
                             $status = 0;
                         }
                     }
                     $rply = Gmsg::create(array("status" => $status, "cert" => $res));
                     break;
                 case "reverb":
                     $res = $mess;
                     break;
                 default:
                     $status = 0;
                     $res = "Invalid Operation!";
             }
         }
     }
     if (!isset($rply)) {
         $ret = array("status" => $status, "response" => $res);
         $rply = self::create($ret);
         $rply = $sender ? GsonCrypt::seal("{$rply}", "{$sender}") : "{$rply}";
     }
     return $rply;
 }