Skip to content

Commit 1fec9fc

Browse files
committed
fix database to support multiple tokens in the same tx
1 parent 83205de commit 1fec9fc

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

api-server/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ The format is loosely based on [Keep a Changelog](https://keepachangelog.com/en/
88

99
### Added
1010
- New endpoint was added: `/v2/transaction/{id}/output/{idx}`.
11-
- New endpoint was added: `/v2/token/{id}/transactions` will return all transactions related to a token
11+
- New endpoint was added: `/v2/token/{id}/transactions` will return all transactions related to a token.\
12+
Pagination works like the new absolute mode in `/v2/transaction`, using `offset` and `items`.
1213

1314
### Changed
1415
- `/v2/token/ticker/{ticker}` will now return all tokens whose ticker has the specified `{ticker}`

api-server/api-server-common/src/storage/impls/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
1515

16-
pub const CURRENT_STORAGE_VERSION: u32 = 24;
16+
pub const CURRENT_STORAGE_VERSION: u32 = 25;
1717

1818
pub mod in_memory;
1919
pub mod postgres;

api-server/api-server-common/src/storage/impls/postgres/queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,11 +823,11 @@ impl<'a, 'b> QueryFromConnection<'a, 'b> {
823823

824824
self.just_execute(
825825
"CREATE TABLE ml.token_transactions (
826-
tx_global_index bigint PRIMARY KEY,
826+
tx_global_index bigint,
827827
token_id bytea NOT NULL,
828828
block_height bigint NOT NULL,
829829
transaction_id bytea NOT NULL,
830-
UNIQUE (token_id, transaction_id, block_height)
830+
PRIMARY KEY (token_id, transaction_id, block_height)
831831
);",
832832
)
833833
.await?;

api-server/storage-test-suite/src/basic.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,21 @@ where
962962
.unwrap();
963963
}
964964

965+
// make sure we can have two tokens in the same transaction
966+
{
967+
let random_token_id2 = TokenId::random_using(&mut rng);
968+
let tx = token_transactions.first().unwrap();
969+
db_tx
970+
.set_token_transaction_at_height(
971+
random_token_id2,
972+
tx.tx_id,
973+
block_height,
974+
tx.tx_global_index,
975+
)
976+
.await
977+
.unwrap();
978+
}
979+
965980
let len = 5;
966981
let global_idx = 10;
967982
let token_txs =

0 commit comments

Comments
 (0)