Advance the payment virtual machine */
| 25 | |
| 26 | /* Advance the payment virtual machine */ |
| 27 | struct command_result *payment_continue(struct payment *payment) |
| 28 | { |
| 29 | assert(payment->exec_state != INVALID_STATE); |
| 30 | void *op = payment_virtual_program[payment->exec_state++]; |
| 31 | |
| 32 | if (op == OP_NULL) { |
| 33 | plugin_err(pay_plugin->plugin, |
| 34 | "payment_continue reached the end of the virtual " |
| 35 | "machine execution."); |
| 36 | } else if (op == OP_CALL) { |
| 37 | const struct payment_modifier *mod = |
| 38 | (const struct payment_modifier *) |
| 39 | payment_virtual_program[payment->exec_state++]; |
| 40 | |
| 41 | if (mod == NULL) |
| 42 | plugin_err(pay_plugin->plugin, |
| 43 | "payment_continue expected payment_modifier " |
| 44 | "but NULL found"); |
| 45 | |
| 46 | plugin_log(pay_plugin->plugin, LOG_TRACE, "Calling modifier %s", |
| 47 | mod->name); |
| 48 | return mod->step_cb(payment); |
| 49 | } else if (op == OP_IF) { |
| 50 | const struct payment_condition *cond = |
| 51 | (const struct payment_condition *) |
| 52 | payment_virtual_program[payment->exec_state++]; |
| 53 | |
| 54 | if (cond == NULL) |
| 55 | plugin_err(pay_plugin->plugin, |
| 56 | "payment_continue expected pointer to " |
| 57 | "condition but NULL found"); |
| 58 | |
| 59 | plugin_log(pay_plugin->plugin, LOG_TRACE, |
| 60 | "Calling payment condition %s", cond->name); |
| 61 | |
| 62 | const u64 position_iftrue = |
| 63 | (intptr_t)payment_virtual_program[payment->exec_state++]; |
| 64 | |
| 65 | if (cond->condition_cb(payment)) |
| 66 | payment->exec_state = position_iftrue; |
| 67 | |
| 68 | return payment_continue(payment); |
| 69 | } |
| 70 | plugin_err(pay_plugin->plugin, "payment_continue op code not defined"); |
| 71 | return NULL; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | /* Generic handler for RPC failures that should end up failing the payment. */ |
no test coverage detected