Skip to content

Commit b5d0e18

Browse files
authored
Merge pull request #303 from KomodoPlatform/update-db-docs
2 parents c1211a2 + 456611b commit b5d0e18

File tree

2 files changed

+66
-22
lines changed

2 files changed

+66
-22
lines changed

filepathSlugs.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -3942,9 +3942,11 @@
39423942
"nodes",
39433943
"query-4",
39443944
"respose",
3945-
"stats-nodes",
3946-
"query-5",
3947-
"response-4"
3945+
"coin-tables",
3946+
"kmd-block-headers-cache",
3947+
"kmd-tx-address",
3948+
"kmd-tx-cache",
3949+
"kmd-tx-history"
39483950
],
39493951
"src/pages/komodo-defi-framework/tutorials/setup-komodefi-api-aws/index.mdx": [
39503952
"how-to-setup-and-use-the-komodo-de-fi-framework-api-on-an-aws-ec-2-instance",

src/pages/komodo-defi-framework/tutorials/query-the-mm2-database/index.mdx

+61-19
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,26 @@ export const description = "This guide describes how to query the MM2 SQLite dat
33

44
# How to Query the MM2 SQLite Database
55

6-
The Komodo DeFi Framework API stores historical information such as swaps and orders within an SQLite database, located under the DB user data folder (e.g. {'{folder continaing mm2 binary}'}/DB/{'{wallet identifying hex string}'}/MM2.db').
6+
The Komodo DeFi Framework API stores historical information such as swaps and orders within an SQLite database, located under the DB user data folder with each wallet having its own subfolder represented by a hexideciaml string.
7+
This string is shown in the runtime logs of the `kdf` binary as `Public key hash` when it starts up.
8+
9+
```bash
10+
30 08:39:23, mm2:269] AtomicDEX API 2.1.0-beta_a81f2a101 DT 2024-07-26T23:24:52+03:00
11+
30 08:39:23, mm2_main::mm2::lp_native_dex:500] INFO Version: 2.1.0-beta_a81f2a101 DT 2024-07-26T23:24:52+03:00
12+
30 08:39:23, crypto::crypto_ctx:324] INFO Public key hash: 7d6cbdd91788df3b764247721fe12853ce36b03d
13+
```
14+
15+
The default location of this folder for each operating system is:
16+
17+
```bash
18+
- Linux: $HOME/.kdf/DB/{'{wallet identifying hex string}'}/MM2.db'
19+
- MacOS: $HOME/.kdf/DB/{'{wallet identifying hex string}'}/MM2.db'
20+
- Windows: %APPDATA%\kdf\DB\{'{wallet identifying hex string}'}\MM2.db'
21+
```
22+
23+
<Note>
24+
You can define a different location for the DB folder via the [`dbdir` configuration parameter](/komodo-defi-framework/setup/configure-mm2-json/) in your MM2.json file.
25+
</Note>
726
827
There are a variety of methods to query sqlite databases. Examples below show how to do a sqlite query in Linux terminal, but first you might need to install sqlite with `sudo apt install sqlite3`.
928
@@ -52,6 +71,10 @@ This table keeps a detailed record of all swaps performed (including failed) in
5271
| 14 | taker\_coin\_usd\_price | DECIMAL | USD price of taker coin at the time of the swap |
5372
| 15 | taker\_pubkey | DECIMAL | Taker pubkey |
5473
| 16 | maker\_pubkey | DECIMAL | Maker pubkey |
74+
| 17 | maker\_gui | VARCHAR(255) | Maker application |
75+
| 18 | taker\_gui | VARCHAR(255) | Taker application |
76+
| 19 | maker\_version | VARCHAR(255) | Maker KDF binary version |
77+
| 20 | taker\_version | VARCHAR(255) | Taker KDF binary version |
5578
5679
#### Query:
5780
@@ -60,7 +83,7 @@ This table keeps a detailed record of all swaps performed (including failed) in
6083
#### Response:
6184
6285
```bash
63-
8|DGB|DOGE|c9515636-f5a4-4767-a0af-c69e59086899|1678815183|1678815631|200|28|1|DGB||DOGE||0.0108|0.07673|02d8064eece4fa5c0f8dc0267f68cee9bdd527f9e88f3594a323428718c391ecc2|03a93f666b9030958f282edd2904f0a33278c0c676ae132d2094840fe722f011c3
86+
8|DGB|DOGE|c9515636-f5a4-4767-a0af-c69e59086899|1678815183|1678815631|200|28|1|DGB||DOGE||0.0108|0.07673|02d8064eece4fa5c0f8dc0267f68cee9bdd527f9e88f3594a323428718c391ecc2|03a93f666b9030958f282edd2904f0a33278c0c676ae132d2094840fe722f011c3|mm2_777|web_dex web|2.1.0-beta_c5e0e00|2.1.0-beta_af571608c
6487
```
6588
6689
## my\_orders
@@ -116,26 +139,45 @@ This table stores a record of all nodes [added for stats collection](/komodo-def
116139
117140
`37|dragonhound_DEV|104.238.221.61|12D3KooWEnrvbqvtTowYMR8FnBeKtryTj9RcXGx8EPpFZHou2ruP`
118141
119-
## stats\_nodes
142+
## Coin tables
120143
121-
This table stores a record of results returned by registered nodes [tracked for node stats collection](/komodo-defi-framework/api/v20/start_version_stat_collection/) in this pubkey's MM2.db
144+
Additional tables are created for each coin to store supplementary details such as block headers and transaction history. Using KMD as an example, these tables are listed below:
122145
123-
| ID | Name | Type | Description |
124-
| -- | --------- | ------------ | -------------------------------------------- |
125-
| 0 | id | INTEGER | Primary Key |
126-
| 1 | name | VARCHAR(255) | Node name |
127-
| 2 | version | VARCHAR(255) | Node Komodo DeFi Framework API (mm2) version |
128-
| 3 | timestamp | INTEGER | Timestamp |
129-
| 4 | error | VARCHAR(255) | Error details |
146+
### KMD\_block\_headers\_cache
130147
131-
#### Query:
148+
| ID | Name | Type | Description |
149+
| -- | ---- | ------- | ----------- |
150+
| 0 | id | INTEGER | Primary Key |
132151
133-
`sqlite3 ${PATH_TO_MM2_DB_FILE} "SELECT * FROM stats_nodes WHERE name = 'dragonhound_DEV'" LIMIT 3`
152+
### KMD\_tx\_address
134153
135-
#### Response:
154+
1|ecfb45cc5d5fdf34dcc70b0db2a333b143f0b98f9a8470097e3a256c1760b6ff|RUYJYSTuCKm9gouWzQN1LirHFEYThwzA2d
136155
137-
```bash
138-
540|dragonhound_DEV||1638542507|DialFailure
139-
70638|dragonhound_DEV|2.1.4401_mm2.1_87837cb54_Linux_Release|1640270702|
140-
70692|dragonhound_DEV||1640271615|Error on request the peer PeerId("12D3KooWEnrvbqvtTowYMR8FnBeKtryTj9RcXGx8EPpFZHou2ruP"): "Canceled". Request next peer
141-
```
156+
| ID | Name | Type | Description |
157+
| -- | ------------ | ------------ | ------------------------------------------- |
158+
| 0 | id | INTEGER | Primary Key |
159+
| 1 | internal\_id | VARCHAR(255) | A hex string, representative of the address |
160+
| 2 | address | VARCHAR(255) | The coin's wallet address |
161+
162+
### KMD\_tx\_cache
163+
164+
tx\_hash|tx\_hex
165+
166+
| ID | Name | Type | Description |
167+
| -- | -------- | ------------ | ----------------------- |
168+
| 0 | tx\_hash | VARCHAR(255) | A transaction hash |
169+
| 1 | tx\_hex | VARCHAR(255) | Raw hex for transaction |
170+
171+
### KMD\_tx\_history
172+
173+
id|tx\_hash|internal\_id|block\_height|confirmation\_status|token\_id|details\_json
174+
175+
| ID | Name | Type | Description |
176+
| -- | -------------------- | ------------ | ------------------------------------------------------------- |
177+
| 0 | id | INTEGER | Primary Key |
178+
| 1 | tx\_hash | VARCHAR(255) | A transaction hash |
179+
| 2 | internal\_id | VARCHAR(255) | A hex string, representative of the transaction |
180+
| 3 | block\_height | INTEGER | Block height of transaction |
181+
| 4 | confirmation\_status | BOOLEAN | `True` if transaction has completed, `False` if it is pending |
182+
| 5 | token\_id | INTEGER | Number representing the coin type |
183+
| 6 | details\_json | VARCHAR(255) | Transaction details in JSON format |

0 commit comments

Comments
 (0)