A user creates a market (contract) with the question, description, seed amounts.
pub fn create_contract(
ctx: Context<CreateContract>,
props: NewContractProps,
) -> ProgramResult {
...
}
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
pub struct NewContractProps {
// Use the contract's public account address as the contract id.
~~pub id: String,~~
// Creator id is user's public address.
~~pub creator_id: String,~~
pub question: String,
pub description: String,
pub seed_amounts: SeedAmounts,
}
A user makes a bet on a contract
pub fn place_bet(
ctx: Context<PlaceBet>,
props: BetProps
) -> ProgramResult {
...
}
#[derive(Clone, AnchorSerialize, AnchorDeserialize)]
pub struct BetProps {
pub amount: u64,
pub user_id: String,
pub outcome: BetOutcome,
}
The creator resolves a contract
pub fn resolve_contract(...)
Solana contracts should publish their interface so other clients can call them.
Anchor packages this interface in a json file called the IDL, which can be automatically generated from the rust contract. The interface can be unpacked to several client languages like Typescript or Rust.
We can then publish the IDL to the blockchain so anyone using our contract can fetch it.
Anchor gives the framework for running javascript tests that call into the smart contract.
Need to extensively test the public methods.