void apply(database &db, const signed_transaction &t, const options_type &opts) { auto undo_session = db.start_undo_session(!(opts & skip_undo_transaction)); db.pre_apply_transaction(t); db.create<transaction_object>([&](transaction_object &trx) { trx.trx_id = t.id(); trx.block_num = db.head_block().block_num; auto pack_size = fc::raw::pack_size(t); trx.packed_transaction.resize(pack_size); fc::datastream<char *> ds(trx.packed_transaction.data(), pack_size); fc::raw::pack(ds, t); }); for (const auto &op : t.operations) { apply(db, op, opts); } db.post_apply_transaction(t); undo_session.squash(); }
void apply(database &db, const signed_block &b, const options_type &opts) { auto undo_session = db.start_undo_session(!(opts & skip_undo_block)); db.pre_apply_block(b); if (!(opts & skip_validation)) { FC_ASSERT(b.timestamp.sec_since_epoch() % 3 == 0); if (b.block_num() > 1) { idump((b.block_num())); const auto &head = db.head_block(); FC_ASSERT(b.block_num() == head.block_num + 1); FC_ASSERT(b.timestamp >= head.timestamp + fc::seconds(3)); } } db.create<block_object>([&](block_object &obj) { obj.block_num = b.block_num(); obj.block_id = b.id(); obj.ref_prefix = obj.block_id._hash[1]; obj.previous = b.previous; obj.timestamp = b.timestamp; obj.witness = b.witness; obj.transaction_merkle_root = b.transaction_merkle_root; obj.witness_signature = b.witness_signature; obj.transactions.reserve(b.transactions.size()); for (const auto &t : b.transactions) { obj.transactions.emplace_back(t.id()); } }); for (const auto &trx : b.transactions) { apply(db, trx, opts); } db.post_apply_block(b); undo_session.push(); }