Przeglądaj źródła

contract/money/client: SQL table consts.

parazyd 3 lat temu
rodzic
commit
10f69e06f4

+ 67 - 0
src/contract/money/src/client/mod.rs

@@ -0,0 +1,67 @@
+/* This file is part of DarkFi (https://dark.fi)
+ *
+ * Copyright (C) 2020-2023 Dyne.org foundation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+
+//! This module implements the client-side API for this contract's interaction.
+//! What we basically do here is implement an API that creates the necessary
+//! structures and is able to export them to create a DarkFi transaction
+//! object that can be broadcasted to the network when we want to make a
+//! payment with some coins in our wallet.
+//!
+//! Note that this API does not involve any wallet interaction, but only takes
+//! the necessary objects provided by the caller. This is intentional, so we
+//! are able to abstract away any wallet interfaces to client implementations.
+
+// Wallet SQL table constant names. These have to represent the `wallet.sql`
+// SQL schema.
+// TODO: They should also be prefixed with the contract ID to avoid collisions.
+pub const MONEY_INFO_TABLE: &str = "money_info";
+pub const MONEY_INFO_COL_LAST_SCANNED_SLOT: &str = "last_scanned_slot";
+
+pub const MONEY_TREE_TABLE: &str = "money_tree";
+pub const MONEY_TREE_COL_TREE: &str = "tree";
+
+pub const MONEY_KEYS_TABLE: &str = "money_keys";
+pub const MONEY_KEYS_COL_KEY_ID: &str = "key_id";
+pub const MONEY_KEYS_COL_IS_DEFAULT: &str = "is_default";
+pub const MONEY_KEYS_COL_PUBLIC: &str = "public";
+pub const MONEY_KEYS_COL_SECRET: &str = "secret";
+
+pub const MONEY_COINS_TABLE: &str = "money_coins";
+pub const MONEY_COINS_COL_COIN: &str = "coin";
+pub const MONEY_COINS_COL_IS_SPENT: &str = "is_spent";
+pub const MONEY_COINS_COL_SERIAL: &str = "serial";
+pub const MONEY_COINS_COL_VALUE: &str = "value";
+pub const MONEY_COINS_COL_TOKEN_ID: &str = "token_id";
+pub const MONEY_COINS_COL_SPEND_HOOK: &str = "spend_hook";
+pub const MONEY_COINS_COL_USER_DATA: &str = "user_data";
+pub const MONEY_COINS_COL_COIN_BLIND: &str = "coin_blind";
+pub const MONEY_COINS_COL_VALUE_BLIND: &str = "value_blind";
+pub const MONEY_COINS_COL_TOKEN_BLIND: &str = "token_blind";
+pub const MONEY_COINS_COL_SECRET: &str = "secret";
+pub const MONEY_COINS_COL_NULLIFIER: &str = "nullifier";
+pub const MONEY_COINS_COL_LEAF_POSITION: &str = "leaf_position";
+pub const MONEY_COINS_COL_MEMO: &str = "memo";
+
+pub const MONEY_TOKENS_TABLE: &str = "money_tokens";
+pub const MONEY_TOKENS_MINT_AUTHORITY: &str = "mint_authority";
+pub const MONEY_TOKENS_TOKEN_ID: &str = "token_id";
+pub const MONEY_TOKENS_IS_FROZEN: &str = "is_frozen";
+
+pub const MONEY_ALIASES_TABLE: &str = "money_aliases";
+pub const MONEY_ALIASES_COL_ALIAS: &str = "alias";
+pub const MONEY_ALIASES_COL_TOKEN_ID: &str = "token_id";

+ 6 - 2
src/contract/money/src/lib.rs

@@ -53,12 +53,16 @@ impl TryFrom<u8> for MoneyFunction {
 /// Internal contract errors
 /// Internal contract errors
 pub mod error;
 pub mod error;
 
 
+/// Call parameters definitions
+pub mod model;
+
 #[cfg(not(feature = "no-entrypoint"))]
 #[cfg(not(feature = "no-entrypoint"))]
 /// WASM entrypoint functions
 /// WASM entrypoint functions
 pub mod entrypoint;
 pub mod entrypoint;
 
 
-/// Call parameters definitions
-pub mod model;
+#[cfg(feature = "client")]
+/// Client API for interaction with this smart contract
+pub mod client;
 
 
 // These are the different sled trees that will be created
 // These are the different sled trees that will be created
 pub const MONEY_CONTRACT_INFO_TREE: &str = "info";
 pub const MONEY_CONTRACT_INFO_TREE: &str = "info";

+ 7 - 0
src/contract/money/wallet.sql

@@ -38,6 +38,13 @@ CREATE TABLE IF NOT EXISTS money_coins (
 	memo BLOB
 	memo BLOB
 );
 );
 
 
+-- Arbitrary tokens
+CREATE TABLE IF NOT EXISTS money_tokens (
+	mint_authority BLOB PRIMARY KEY NOT NULL,
+	token_id BLOB NOT NULL,
+	is_frozen INTEGER NOT NULL
+);
+
 -- The token aliases in our wallet
 -- The token aliases in our wallet
 CREATE TABLE IF NOT EXISTS money_aliases (
 CREATE TABLE IF NOT EXISTS money_aliases (
 	alias BLOB PRIMARY KEY NOT NULL,
 	alias BLOB PRIMARY KEY NOT NULL,