Transaction Types
Transaction types are a functionality provided by Dragonchain to give the user direct control over the transactions added to their blockchain. By design, the chain will not accept any transactions unless attached to a registered transaction type on that business chain. Transactions can be grouped logically using this feature, allowing the user to index data for more precise and efficient search functionality within their applications and systems.
Creating Transaction Types
Transaction types can be created with dctl
and used to group transaction data by type or function.
$ dctl transactionType create "my-transaction-type"
{
"status": 200,
"response": {
"success": true
},
"ok": true
}
After creating a transaction type, it can be used in transactions.
$ dctl transaction create "my-transaction-type" '{ "banana": 4 }'
{
"status": 201,
"response": {
"transaction_id": "b09ef198-7bb9-40c4-990b-097b3bac93c5"
},
"ok": true
}
Custom Indexes
To query fields within the transaction payload, new custom indexes must be specified when creating the transaction type.
$ dctl transactionType create "apple" -c '[{"fieldName":"fruit","path":"banana","type":"text"}]'
{
"status": 200,
"response": {
"success": true
},
"ok": true
}
The path provided in a custom index is used to search the payload and index the value. For instance, a transaction with banana: 4
in the payload is found by a search for transactions where banana=4
.
$ dctl transaction create "apple" '{ "banana":"4" }'
{
"status": 201,
"response": {
"transaction_id": "ac08cc98-ed5b-4737-aa65-eafe55b136fb"
},
"ok": true
}
$ dctl transaction query "apple" "@fruit:'4'"
{
"status": 200,
"response": {
"total": 1,
"results": [
{
"version": "2",
"dcrn": "Transaction::L1::FullTransaction",
"header": {
"txn_type": "apple",
"dc_id": "28GiivQE5m8a9oyvFD33JgwnBpgyZp2RxtTVFGjcRPVDJ",
"txn_id": "3efc3d7a-f95f-4f61-9962-74c639271c54",
"block_id": "28165850",
"timestamp": "1573067465",
"tag": "",
"invoker": ""
},
"payload": {
"banana": "4"
},
"proof": {
"full": "fSrf6QvG66KnTeBQhb5WXrzmTr79J9oYsxwUnDVJhNk=",
"stripped": "MEUCIQDducNDgDSfNxaJECO52uYsokA+Fi8epKwABF6gjbZ6lQIgZ9Z5T3IPpMI8CSuWjZ6fqT2+IfAx/5w48BKRiWUI3E8="
}
}
]
},
"ok": true
}
Searching Transaction Types
Dragonchain makes use of Redisearch for our indexing solution. All indexes on a chain use the Redisearch types Text
, Tag
, or Number
. The syntax of these searches can be found on Redisearch’s main site. Each type of index has different options that can be configured when the index is created.
By default, the chain indexes block_id
, tag
, invoker
, and timestamp
for every incoming transaction. These indexes are stored under the transaction type used.
For example, transactions can be queried between two unix timestamps:
$ dctl transaction query "myTransactionType" "@timestamp:[1573064499 1573064499]"
{
"status": 200,
"response": {
"total": 1,
"results": [
{
"version": "2",
"dcrn": "Transaction::L1::FullTransaction",
"header": {
"txn_type": "myTransactionType",
"dc_id": "28GiivQE5m8a9oyvFD33JgwnBpgyZp2RxtTVFGjcRPVDJ",
"txn_id": "b09ef198-7bb9-40c4-990b-097b3bac93c5",
"block_id": "28165256",
"timestamp": "1573064499",
"tag": "",
"invoker": ""
},
"payload": {
"a": {
"really": {
"complex": {
"payload": {
"banana": 4
}
}
}
}
},
"proof": {
"full": "Z0WJZkawekUDJoHjN7lH7+IB3yTP7Om2KG0noOp57Ao=",
"stripped": "MEUCIQD8IKhHu2OUVprC3w7EJOP86Spjiv6RQT6f32rou+U4VQIgPbA29jw1pBf8avZRraKAzbixFapfsZOL8bjfNwWaCRs="
}
}
]
},
"ok": true
}
This range operator can be used on other numeric fields:
$ dctl transaction query "myTransactionType" "@block_id:[28165256 28165256]"
{
"status": 200,
"response": {
"total": 1,
"results": [
{
"version": "2",
"dcrn": "Transaction::L1::FullTransaction",
"header": {
"txn_type": "myTransactionType",
"dc_id": "28GiivQE5m8a9oyvFD33JgwnBpgyZp2RxtTVFGjcRPVDJ",
"txn_id": "b09ef198-7bb9-40c4-990b-097b3bac93c5",
"block_id": "28165256",
"timestamp": "1573064499",
"tag": "",
"invoker": ""
},
"payload": {
"a": {
"really": {
"complex": {
"payload": {
"banana": 4
}
}
}
}
},
"proof": {
"full": "Z0WJZkawekUDJoHjN7lH7+IB3yTP7Om2KG0noOp57Ao=",
"stripped": "MEUCIQD8IKhHu2OUVprC3w7EJOP86Spjiv6RQT6f32rou+U4VQIgPbA29jw1pBf8avZRraKAzbixFapfsZOL8bjfNwWaCRs="
}
}
]
},
"ok": true
}
Searching Custom Indexes
To further extend indexing, any field in the transaction payload can be indexed as a text
, tag
, or number
Redisearch field.
$ dctl transactionType create "apple" -c '[{"fieldName":"fruit","path":"banana","type":"text"},{"fieldName":"vegetable","path":"lettuce","type":"tag"},{"fieldName":"dairy","path":"cheese","type":"number"}]'
{
"status": 200,
"response": {
"success": true
},
"ok": true
}
$ dctl transaction create "apple" '{ "banana":"4", "lettuce":"crisp", "cheese":4567 }'
{
"status": 201,
"response": {
"transaction_id": "665541ef-7a68-472d-b4f1-c75484a7f8f7"
},
"ok": true
}
Tag Query
$ dctl transaction query "apple" "@vegetable:{crisp}"
{
"status": 200,
"response": {
"total": 1,
"results": [
{
"version": "2",
"dcrn": "Transaction::L1::FullTransaction",
"header": {
"txn_type": "apple",
"dc_id": "28GiivQE5m8a9oyvFD33JgwnBpgyZp2RxtTVFGjcRPVDJ",
"txn_id": "665541ef-7a68-472d-b4f1-c75484a7f8f7",
"block_id": "28167573",
"timestamp": "1573076083",
"tag": "",
"invoker": ""
},
"payload": {
"banana": "4",
"lettuce": "crisp",
"cheese": 4567
},
"proof": {
"full": "BGHz+yb+lrasHKNbl46awH1bqPYBb+HfZiqecBV31Bs=",
"stripped": "MEUCIQDWgiKuN4JJMU8WSGe0HnNipPgH/O8S+uVuk6YuB/K2swIgEw6OhNrDWN1rcAr6UBYBDzVvranlBsbJnuP1uXagLa0="
}
}
]
},
"ok": true
}
Numeric Query
$ dctl transaction query "apple" "@dairy:[4000 5000]"
{
"status": 200,
"response": {
"total": 1,
"results": [
{
"version": "2",
"dcrn": "Transaction::L1::FullTransaction",
"header": {
"txn_type": "apple",
"dc_id": "28GiivQE5m8a9oyvFD33JgwnBpgyZp2RxtTVFGjcRPVDJ",
"txn_id": "665541ef-7a68-472d-b4f1-c75484a7f8f7",
"block_id": "28167573",
"timestamp": "1573076083",
"tag": "",
"invoker": ""
},
"payload": {
"banana": "4",
"lettuce": "crisp",
"cheese": 4567
},
"proof": {
"full": "BGHz+yb+lrasHKNbl46awH1bqPYBb+HfZiqecBV31Bs=",
"stripped": "MEUCIQDWgiKuN4JJMU8WSGe0HnNipPgH/O8S+uVuk6YuB/K2swIgEw6OhNrDWN1rcAr6UBYBDzVvranlBsbJnuP1uXagLa0="
}
}
]
},
"ok": true
}