change simple apps to use TxRecords

This commit is contained in:
William Banfield
2022-03-08 17:24:25 -05:00
parent cdae5e325b
commit d2ae45324c
2 changed files with 22 additions and 5 deletions
+14 -4
View File
@@ -284,7 +284,7 @@ func (app *Application) PrepareProposal(req types.RequestPrepareProposal) types.
app.mu.Lock()
defer app.mu.Unlock()
return types.ResponsePrepareProposal{BlockData: app.substPrepareTx(req.BlockData)}
return types.ResponsePrepareProposal{TxRecords: app.substPrepareTx(req.Txs)}
}
func (*Application) ProcessProposal(req types.RequestProcessProposal) types.ResponseProcessProposal {
@@ -432,14 +432,24 @@ func (app *Application) execPrepareTx(tx []byte) *types.ExecTxResult {
// substPrepareTx subst all the preparetx in the blockdata
// to null string(could be any arbitrary string).
func (app *Application) substPrepareTx(blockData [][]byte) [][]byte {
func (app *Application) substPrepareTx(blockData [][]byte) []*types.TxRecord {
// TODO: this mechanism will change with the current spec of PrepareProposal
// We now have a special type for marking a tx as changed
trs := make([]*types.TxRecord, len(blockData))
for i, tx := range blockData {
if isPrepareTx(tx) {
blockData[i] = make([]byte, len(tx))
trs[i] = &types.TxRecord{
Tx: make([]byte, len(tx)),
Action: types.TxRecord_ADDED,
}
continue
}
trs[i] = &types.TxRecord{
Tx: tx,
Action: types.TxRecord_UNMODIFIED,
}
}
return blockData
return trs
}
+8 -1
View File
@@ -300,7 +300,14 @@ func (app *Application) ApplySnapshotChunk(req abci.RequestApplySnapshotChunk) a
}
func (app *Application) PrepareProposal(req abci.RequestPrepareProposal) abci.ResponsePrepareProposal {
return abci.ResponsePrepareProposal{BlockData: req.BlockData}
trs := make([]*abci.TxRecord, len(req.Txs))
for i, tx := range req.Txs {
trs[i] = &abci.TxRecord{
Tx: tx,
Action: abci.TxRecord_UNMODIFIED,
}
}
return abci.ResponsePrepareProposal{TxRecords: trs}
}
// ProcessProposal implements part of the Application interface.