int tx_init(shpeer_t *cli_peer, tx_t *tx, int tx_op) { shkey_t *key; txop_t *op; int tx_len; int err; if (!tx) return (SHERR_INVAL); op = get_tx_op(tx_op); if (!op) return (SHERR_INVAL); if (op->op_size == 0) return (0); tx->tx_op = tx_op; if (op->op_init) { err = op->op_init(cli_peer, tx); if (err) return (err); } if (tx->tx_flag & TXF_WARD) { err = txward_init(tx); if (err) return (err); } err = local_transid_generate(tx_op, tx); if (err) return (err); /* scrypt error */ /* generate transaction key */ memcpy(&tx->tx_key, ashkey_blank(), sizeof(tx->tx_key)); key = shkey_bin((char *)tx, op->op_keylen ? op->op_keylen : op->op_size); memcpy(&tx->tx_key, key, sizeof(tx->tx_key)); shkey_free(&key); return (0); }
/** * Creates a new bond with the local shared as sender. * @note Set the bond state to confirm to initiate transaction. */ tx_bond_t *create_bond(shkey_t *bond_key, double duration, double fee, double basis) { bond = (tx_bond_t *)calloc(1, sizeof(tx_bond_t)); if (!bond) return (SHERR_NOMEM); local_transid_generate(TX_BOND, &bond->tx); bond->bond_stamp = shtime64(); bond->bond_stamp = shtime_adj(bond->bond_stamp, duration); bond->bond_credit = (uint64_t)(fee / 0.00000001); bond->bond_basis = (uint32_t)(basis * 10000); bond->bond_state = TXBOND_PENDING; /* authenticate bond info */ generate_bond_signature(bond); err = tx_init(NULL, (tx_t *)bond, TX_BOND); if (err) return (err); return (bond); }