-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
143eac2
commit 5c276ee
Showing
55 changed files
with
1,571 additions
and
614 deletions.
There are no files selected for viewing
File renamed without changes.
29 changes: 29 additions & 0 deletions
29
applications/tari_collectibles/src-tauri/migrations/2021-12-03-121212_add_721_tokens/up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-- // Copyright 2021. The Tari Project | ||
-- // | ||
-- // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
-- // following conditions are met: | ||
-- // | ||
-- // 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
-- // disclaimer. | ||
-- // | ||
-- // 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the | ||
-- // following disclaimer in the documentation and/or other materials provided with the distribution. | ||
-- // | ||
-- // 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote | ||
-- // products derived from this software without specific prior written permission. | ||
-- // | ||
-- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
-- // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
-- // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
-- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
-- // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
-- // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
-- // USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
create table tip721_tokens ( | ||
id blob not null primary key, | ||
address_id blob not null references addresses(id), | ||
token_id BigInt not null, | ||
is_deleted boolean not null, | ||
token text not null | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
applications/tari_collectibles/src-tauri/src/commands/tip004/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Copyright 2021. The Tari Project | ||
// | ||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
// following conditions are met: | ||
// | ||
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
// disclaimer. | ||
// | ||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the | ||
// following disclaimer in the documentation and/or other materials provided with the distribution. | ||
// | ||
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote | ||
// products derived from this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
use crate::{ | ||
app_state::ConcurrentAppState, | ||
status::Status, | ||
storage::{ | ||
models::{address_row::AddressRow, tip721_token_row::Tip721TokenRow}, | ||
AddressesTableGateway, AssetsTableGateway, CollectiblesStorage, StorageTransaction, | ||
Tip721TokensTableGateway, | ||
}, | ||
}; | ||
use prost::Message; | ||
use tari_common_types::types::PublicKey; | ||
use tari_dan_common_types::proto::tips::tip004; | ||
use tari_utilities::{hex::Hex, ByteArray}; | ||
use uuid::Uuid; | ||
|
||
#[tauri::command] | ||
pub(crate) async fn tip004_mint_token( | ||
asset_public_key: String, | ||
token: String, | ||
state: tauri::State<'_, ConcurrentAppState>, | ||
) -> Result<(), Status> { | ||
let _wallet_id = state | ||
.current_wallet_id() | ||
.await | ||
.ok_or_else(Status::unauthorized)?; | ||
let asset_public_key = PublicKey::from_hex(&asset_public_key)?; | ||
let mut client = state.connect_validator_node_client().await?; | ||
let db = state.create_db().await?; | ||
let tx = db.create_transaction()?; | ||
let _asset = db.assets().find_by_public_key(&asset_public_key, &tx)?; | ||
drop(tx); | ||
|
||
// TODO: get signature | ||
let args = tip004::MintRequest { | ||
token, | ||
owner: Vec::from(asset_public_key.as_bytes()), | ||
}; | ||
let mut bytes = vec![]; | ||
args.encode(&mut bytes)?; | ||
let result = client | ||
.invoke_method(asset_public_key, 4, "mint".to_string(), bytes) | ||
.await?; | ||
dbg!(&result); | ||
Ok(()) | ||
} | ||
|
||
#[tauri::command] | ||
pub(crate) async fn tip004_list_tokens( | ||
asset_public_key: String, | ||
state: tauri::State<'_, ConcurrentAppState>, | ||
) -> Result<Vec<(Tip721TokenRow, AddressRow)>, Status> { | ||
let wallet_id = state | ||
.current_wallet_id() | ||
.await | ||
.ok_or_else(Status::unauthorized)?; | ||
let asset_public_key = PublicKey::from_hex(&asset_public_key)?; | ||
let db = state.create_db().await?; | ||
let tx = db.create_transaction()?; | ||
let asset = db.assets().find_by_public_key(&asset_public_key, &tx)?; | ||
let addresses = db | ||
.addresses() | ||
.find_by_asset_and_wallet(asset.id, wallet_id, &tx)?; | ||
let mut client = state.connect_validator_node_client().await?; | ||
let mut token_ids = vec![]; | ||
for address in addresses { | ||
let args = tip004::BalanceOfRequest { | ||
owner: Vec::from(address.public_key.as_bytes()), | ||
}; | ||
let result = client | ||
.invoke_read_method( | ||
asset_public_key.clone(), | ||
4, | ||
"balance_of".to_string(), | ||
args.encode_to_vec(), | ||
) | ||
.await?; | ||
dbg!(&result); | ||
db.tip721_tokens().delete_all_for_address(address.id, &tx)?; | ||
if let Some(result) = result { | ||
let balance_of: tip004::BalanceOfResponse = Message::decode(&*result)?; | ||
for index in 0..balance_of.num_tokens { | ||
let args = tip004::TokenOfOwnerByIndexRequest { | ||
owner: Vec::from(address.public_key.as_bytes()), | ||
index, | ||
}; | ||
let token_result = client | ||
.invoke_read_method( | ||
asset_public_key.clone(), | ||
4, | ||
"token_of_owner_by_index".to_string(), | ||
args.encode_to_vec(), | ||
) | ||
.await?; | ||
if let Some(token_result) = token_result { | ||
let token_data: tip004::TokenOfOwnerByIndexResponse = Message::decode(&*token_result)?; | ||
|
||
let token_row = Tip721TokenRow { | ||
id: Uuid::new_v4(), | ||
address_id: address.id, | ||
token_id: token_data.token_id, | ||
token: token_data.token.clone(), | ||
}; | ||
|
||
db.tip721_tokens().insert(&token_row, &tx)?; | ||
token_ids.push((token_row, address.clone())); | ||
} | ||
} | ||
} | ||
} | ||
tx.commit()?; | ||
|
||
Ok(token_ids) | ||
} |
77 changes: 77 additions & 0 deletions
77
applications/tari_collectibles/src-tauri/src/commands/tip721/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2021. The Tari Project | ||
// | ||
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the | ||
// following conditions are met: | ||
// | ||
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following | ||
// disclaimer. | ||
// | ||
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the | ||
// following disclaimer in the documentation and/or other materials provided with the distribution. | ||
// | ||
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote | ||
// products derived from this software without specific prior written permission. | ||
// | ||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | ||
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
use crate::{ | ||
app_state::ConcurrentAppState, | ||
status::Status, | ||
storage::{AddressesTableGateway, AssetsTableGateway, CollectiblesStorage}, | ||
}; | ||
use prost::Message; | ||
use tari_common_types::types::PublicKey; | ||
use tari_dan_common_types::proto::tips::tip721; | ||
use tari_utilities::{hex::Hex, ByteArray}; | ||
use uuid::Uuid; | ||
|
||
#[tauri::command] | ||
pub(crate) async fn tip721_transfer_from( | ||
asset_public_key: String, | ||
token_id: u64, | ||
send_to_address: String, | ||
from_address_id: Uuid, | ||
state: tauri::State<'_, ConcurrentAppState>, | ||
) -> Result<(), Status> { | ||
let wallet_id = state | ||
.current_wallet_id() | ||
.await | ||
.ok_or_else(Status::unauthorized)?; | ||
let asset_public_key = PublicKey::from_hex(&asset_public_key)?; | ||
let send_to_address = PublicKey::from_hex(&send_to_address)?; | ||
let db = state.create_db().await?; | ||
let tx = db.create_transaction()?; | ||
let asset = db.assets().find_by_public_key(&asset_public_key, &tx)?; | ||
let asset_addresses = db | ||
.addresses() | ||
.find_by_asset_and_wallet(asset.id, wallet_id, &tx)?; | ||
let from_address = asset_addresses | ||
.into_iter() | ||
.find(|aa| aa.id == from_address_id) | ||
.ok_or_else(|| Status::not_found("address".to_string()))?; | ||
drop(tx); | ||
let mut client = state.connect_validator_node_client().await?; | ||
let transfer_request = tip721::TransferFromRequest { | ||
from: Vec::from(from_address.public_key.as_bytes()), | ||
to: Vec::from(send_to_address.as_bytes()), | ||
token_id, | ||
}; | ||
let transfer_request = transfer_request.encode_to_vec(); | ||
|
||
let res = client | ||
.invoke_method( | ||
asset_public_key.clone(), | ||
721, | ||
"transfer_from".to_string(), | ||
transfer_request, | ||
) | ||
.await?; | ||
dbg!(&res); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.