int txop_ward_confirm(shpeer_t *peer, tx_ward_t *ward) { tx_context_t *ctx; tx_t *tx; int err; #if 0 /* verify identity exists */ ctx = (tx_context_t *)tx_load(TX_CONTEXT, &ward->ward_ctx); if (!ctx) return (SHERR_NOKEY); /* .. */ pstore_free(ctx); err = confirm_signature(&ward->ward_sig, shpeer_kpriv(&ward->ward_peer), shkey_hex(&ward->ward_key)); pstore_free(tx); if (err) return (err); err = inittx_context(ctx, get_tx_key(ward), ashkey_uniq()); if (err) return (err); #endif return (0); }
/** * Confirm a ward's application on a transaction. */ int txward_confirm(tx_t *tx) { tx_ward_t *ward; tx_context_t *ctx; shkey_t *tx_key; int err; tx_key = get_tx_key(tx); if (!tx_key) return (SHERR_INVAL); ward = (tx_ward_t *)tx_load(TX_WARD, tx_key); if (!ward) return (SHERR_NOKEY); /* incomplete scope */ ctx = (tx_context_t *)tx_load(TX_CONTEXT, tx_key); if (!ctx) return (SHERR_AGAIN); /* transaction ward is applied. */ /* validate context to invalidate ward. */ err = txward_context_confirm(ward, ctx); pstore_free(ctx); if (err) return (err); return (0); }
void free_bond(tx_bond_t **bond_p) { tx_bond_t *bond; if (!bond_p) return; bond = *bond_p; *bond_p = NULL; if (!bond) return; pstore_free(bond); }
void free_asset(tx_asset_t **asset_p) { tx_asset_t *asset; if (!asset_p) return; asset = *asset_p; *asset_p = NULL; if (!asset) return; pstore_free(asset); }
/** * Obtain the root transaction key of the transaction hierarchy. * @returns An unallocated tx key or NULL if tx is the root tx. */ shkey_t *get_tx_key_root(tx_t *tx) { static shkey_t ret_key; tx_t *t_tx; tx_t *p_tx; t_tx = tx; memcpy(&ret_key, ashkey_blank(), sizeof(ret_key)); while ((p_tx = get_tx_parent(t_tx))) { if (t_tx != tx) pstore_free(t_tx); t_tx = p_tx; memcpy(&ret_key, get_tx_key(t_tx), sizeof(ret_key)); } return (&ret_key); }
int tx_recv(shpeer_t *cli_peer, tx_t *tx) { tx_ledger_t *l; tx_t *rec_tx; txop_t *op; int err; if (!tx) return (SHERR_INVAL); #if 0 if (ledger_tx_load(shpeer_kpriv(cli_peer), tx->hash, tx->tx_stamp)) { fprintf(stderr, "DEBUG: tx_recv: skipping duplicate tx '%s'\n", tx->hash); return (SHERR_NOTUNIQ); } #endif op = get_tx_op(tx->tx_op); if (!op) return (SHERR_INVAL); if (tx->tx_flag & TXF_WARD) { err = txward_confirm(tx); if (err) return (err); } /* check for dup in ledger (?) */ rec_tx = (tx_t *)tx_load(tx->tx_op, get_tx_key(tx)); if (!rec_tx) { rec_tx = (tx_t *)calloc(1, op->op_size); if (!rec_tx) return (SHERR_NOMEM); memcpy(rec_tx, tx, op->op_size); #if 0 err = tx_init(cli_peer, rec_tx); if (err) { pstore_free(rec_tx); return (err); } #endif err = tx_save(rec_tx); if (err) { pstore_free(rec_tx); return (err); } } if (op->op_recv) { err = op->op_recv(cli_peer, tx); if (err) { pstore_free(rec_tx); return (err); } } pstore_free(rec_tx); if (is_tx_stored(tx->tx_op)) { l = ledger_load(shpeer_kpriv(cli_peer), shtime()); if (l) { ledger_tx_add(l, tx); ledger_close(l); } } return (0); }