Skip to content

Commit

Permalink
Added --notify-at 3 (unlocked).
Browse files Browse the repository at this point in the history
  • Loading branch information
d4ndox committed May 25, 2024
1 parent 9ba533f commit e23661b
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ Usage: mnp [OPTION] [TXID]
--account [ACCOUNT]
Monero account number. 0 = default.

--notify-at [0,1,2] default = confirmed
--notify-at [0,1,2,3] default = confirmed
0, none
1, txpool
2, confirmed
3, unlocked

--confirmation [n]
amount of blocks needed to confirm transaction.
Expand Down
3 changes: 2 additions & 1 deletion globaldefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define MAX_ADDR_SIZE (96)
#define MAX_PAYID_SIZE (16)
#define MAX_TXID_SIZE (64)
#define VERSION "0.1.1"
#define VERSION "0.1.2"
#define DEBUG (0)
#define CONFIG_FILE ".mnp.ini"
#define TMP_TXID_FILE "/tmp/mnp.txid"
Expand Down Expand Up @@ -35,6 +35,7 @@ enum notify {
NONE,
TXPOOL,
CONFIRMED,
UNLOCKED,
};

#define GET_HEIGHT_CMD "get_height"
Expand Down
39 changes: 32 additions & 7 deletions mnp.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ static char *amount(const struct rpc_wallet *monero_wallet);
static char *address(const struct rpc_wallet *monero_wallet);
static char *payid(const struct rpc_wallet *monero_wallet);
static char *confirm(const struct rpc_wallet *monero_wallet);
static char *locked(const struct rpc_wallet *monero_wallet);

int main(int argc, char **argv)
{
Expand All @@ -108,6 +109,7 @@ int main(int argc, char **argv)
char *workdir = NULL;
char *transferdir = NULL;
char *paymentdir = NULL;
char *locked0 = "true";
int init = 0;
int keep_open = 0;
int cleanup = 0;
Expand Down Expand Up @@ -162,9 +164,9 @@ int main(int argc, char **argv)
break;
case 'o':
notify = atoi(optarg);
if (notify > CONFIRMED) {
syslog(LOG_USER | LOG_ERR, "--notify-at out of range [0,1,2]");
fprintf(stderr, "mnp: --notify-at out of range [0,1,2]\n");
if (notify > UNLOCKED) {
syslog(LOG_USER | LOG_ERR, "--notify-at out of range [0,1,2,3]");
fprintf(stderr, "mnp: --notify-at out of range [0,1,2,3]\n");
closelog();
exit(EXIT_FAILURE);
}
Expand Down Expand Up @@ -276,6 +278,7 @@ int main(int argc, char **argv)
monero_wallet[i].iaddr = NULL;
monero_wallet[i].amount = NULL;
monero_wallet[i].conf = NULL;
monero_wallet[i].locked = NULL;
monero_wallet[i].fifo = NULL;
monero_wallet[i].idx = 0;
monero_wallet[i].reply = NULL;
Expand Down Expand Up @@ -424,6 +427,7 @@ int main(int argc, char **argv)
monero_wallet[GET_TXID].saddr = delQuotes(address(&monero_wallet[GET_TXID]));
monero_wallet[GET_TXID].payid = delQuotes(payid(&monero_wallet[GET_TXID]));
monero_wallet[GET_TXID].conf = confirm(&monero_wallet[GET_TXID]);
monero_wallet[GET_TXID].locked = locked(&monero_wallet[GET_TXID]);

if (strcmp(monero_wallet[GET_TXID].payid, PAYNULL)) {
asprintf(&monero_wallet[GET_TXID].fifo, "%s/%s/%s",
Expand Down Expand Up @@ -469,6 +473,9 @@ int main(int argc, char **argv)
case CONFIRMED:
jail = 1;
break;
case UNLOCKED:
jail = 1;
break;
default:
syslog(LOG_USER | LOG_ERR, "Error, check --notify-at x\n");
fprintf(stderr, "mnp: error, check --notify-at x\n");
Expand All @@ -477,6 +484,8 @@ int main(int argc, char **argv)
break;
}

running = jail;

/* JAIL starts here */
while (running) {
if (0 > (ret = rpc_call(&monero_wallet[GET_TXID]))) {
Expand All @@ -490,13 +499,18 @@ int main(int argc, char **argv)

monero_wallet[GET_TXID].conf = confirm(&monero_wallet[GET_TXID]);
if (monero_wallet[GET_TXID].conf == NULL) asprintf(&monero_wallet[GET_TXID].conf, "0");
monero_wallet[GET_TXID].locked = locked(&monero_wallet[GET_TXID]);

/* release "amount" out of jail */
if (atoi(monero_wallet[GET_TXID].conf) >= confirmation) {
if (notify == UNLOCKED) {
if (strncmp(monero_wallet[GET_TXID].locked, "false", MAX_TXID_SIZE) == 0) {
jail = 0;
}
} else if (atoi(monero_wallet[GET_TXID].conf) >= confirmation) {
jail = 0;
} else if (notify != TXPOOL) {
sleep(SLEEPTIME);
}

sleep(SLEEPTIME);
running = jail;
}

Expand Down Expand Up @@ -575,6 +589,16 @@ static char *confirm(const struct rpc_wallet *monero_wallet)
return cJSON_Print(confirmations);
}

static char *locked(const struct rpc_wallet *monero_wallet)
{
assert (monero_wallet != NULL);

cJSON *result = cJSON_GetObjectItem(monero_wallet->reply, "result");
cJSON *transfer = cJSON_GetObjectItem(result, "transfer");
cJSON *locked = cJSON_GetObjectItem(transfer, "locked");

return cJSON_Print(locked);
}

/*
* Print user help.
Expand Down Expand Up @@ -602,10 +626,11 @@ static void usage(int status)
" rpc port to cennect to.\n\n"
" -w, --workdir [WORKDIR]\n"
" place to create the work directory.\n\n"
" --notify-at [0,1,2] default = confirmed\n"
" --notify-at [0,1,2,3] default = confirmed\n"
" 0, none\n"
" 1, txpool\n"
" 2, confirmed\n\n"
" 3, unlocked\n\n"
" --confirmation [n] default = 1\n"
" amount of blocks needed to confirm transaction.\n\n"
" --keep-open\n"
Expand Down
1 change: 1 addition & 0 deletions rpc_call.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct rpc_wallet {
char *iaddr;
char *amount;
char *conf;
char *locked;
char *fifo;
int idx;
cJSON *reply;
Expand Down

0 comments on commit e23661b

Please sign in to comment.