コード例 #1
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);
}
コード例 #2
0
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);
}
コード例 #3
0
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);
}