use std::collections::BTreeMap;
use async_graphql::{Request, Response};
use linera_base::{
abi::{ContractAbi, ServiceAbi},
data_types::U128,
identifiers::{AccountOwner, ApplicationId, ChainId},
};
use linera_sdk_derive::GraphQLMutationRootInCrate;
use serde::{Deserialize, Serialize};
pub use super::fungible::Account;
#[derive(Clone, Debug, Deserialize, Eq, Ord, PartialEq, PartialOrd, Serialize)]
pub struct WrappedParameters {
pub ticker_symbol: String,
pub decimals: u8,
pub mint_chain_id: ChainId,
pub evm_token_address: [u8; 20],
pub evm_source_chain_id: u64,
}
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub struct BurnEvent {
pub target: [u8; 20],
pub amount: U128,
}
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[allow(missing_docs)]
pub struct InitialState {
pub accounts: BTreeMap<AccountOwner, U128>,
}
#[derive(Debug, Default)]
pub struct InitialStateBuilder {
account_balances: BTreeMap<AccountOwner, U128>,
}
impl InitialStateBuilder {
pub fn with_account(mut self, account: AccountOwner, balance: U128) -> Self {
self.account_balances.insert(account, balance);
self
}
pub fn build(&self) -> InitialState {
InitialState {
accounts: self.account_balances.clone(),
}
}
}
#[derive(Debug, Deserialize, Serialize, Default)]
#[allow(missing_docs)]
pub enum FungibleResponse {
#[default]
Ok,
Balance(U128),
TickerSymbol(String),
}
#[derive(Debug, Deserialize, Serialize, GraphQLMutationRootInCrate)]
#[allow(missing_docs)]
pub enum WrappedFungibleOperation {
Balance { owner: AccountOwner },
TickerSymbol,
Approve {
owner: AccountOwner,
spender: AccountOwner,
allowance: U128,
},
Transfer {
owner: AccountOwner,
amount: U128,
target_account: Account,
},
TransferFrom {
owner: AccountOwner,
spender: AccountOwner,
amount: U128,
target_account: Account,
},
Claim {
source_account: Account,
amount: U128,
target_account: Account,
},
Mint {
target_account: Account,
amount: U128,
},
Burn { owner: AccountOwner, amount: U128 },
RegisterAuthorizedCaller { app_id: ApplicationId },
}
#[derive(Debug, Deserialize, Serialize)]
#[allow(missing_docs)]
pub enum Message {
Credit {
target: AccountOwner,
amount: U128,
source: AccountOwner,
},
Withdraw {
owner: AccountOwner,
amount: U128,
target_account: Account,
},
}
pub struct WrappedFungibleTokenAbi;
impl ContractAbi for WrappedFungibleTokenAbi {
type Operation = WrappedFungibleOperation;
type Response = FungibleResponse;
}
impl ServiceAbi for WrappedFungibleTokenAbi {
type Query = Request;
type QueryResponse = Response;
}