It should be trivial to create a simple key-value database anyone could write to… for a fee.
The below contract should allow anyone to create an entry by sending their data in an NFT commitment of any CashToken category. The party creating the record my specify how long they’d like the record to persist by specifying the number of blocks as sats.
Rather than collect data from a custom indexer, dapps could retrieve data from any Bitcoin Cash indexer by getting the NFT balance of the address for the contract corresponding to the key of interest.
Obviously, records would be limited to the current commitment length (currently 40 bytes). And a minimum storage period of 800 blocks (or the current token output minimum value).
The burning mechanism is based on @dagurval 's TokenBurner contract.
pragma cashscript 0.11.0;
// Small Index
//
// A subscription based key-value index
//
contract index(bytes key) {
// Secure outputs with data in token commitments for a given key.
//
// All entries pay a fixed storage fee of 1 satoshi per block.
//
// If an entry has expired, miners may drop it.
//
// Miners can drop many expired entires at once.
//
function drop() {
// Assure the key is not empty.
// OP_SIZE OP_NIP OP_VERIFY
require(bool(key.length));
// Require each input age be higher than the utxo value
// OP_INPUTINDEX OP_UTXOVALUE OP_CHECKSEQUENCEVERIFY OP_DROP
require(tx.age >= tx.inputs[this.activeInputIndex].value);
// See TokenBurner - Dagur Valberg Johannsson
//
// Require a single output
// OP_TXOUTPUTCOUNT OP_1 OP_NUMEQUALVERIFY
require(tx.outputs.length == 1);
// Without BCH
// OP_0 OP_OUTPUTVALUE OP_0 OP_NUMEQUALVERIFY
require(tx.outputs[0].value == 0);
// Without tokens
// OP_0 OP_OUTPUTTOKENCATEGORY OP_0 OP_EQUALVERIFY
require(tx.outputs[0].tokenCategory == 0x);
// As an empty OP_RETURN
// OP_0 OP_OUTPUTBYTECODE 6a OP_EQUAL
require(tx.outputs[0].lockingBytecode == 0x6a);
}
}