Integration with the Protocol

At iCoordinates.xyz, we're committed to fostering a vibrant and interactive community for our coordinates owners. To enhance this experience, we've introduced a grants program aimed at supporting various creative projects. These projects should be designed to provide added value and benefits to our coordinates owners, enriching their engagement with the platform. If you have a creative project that aligns with our mission and would like to integrate with the iCoordinates protocol to access information related to coordinate accounts, we're here to assist you. Below, you'll find a code snippet that demonstrates how to effectively utilize our protocol to obtain coordinate account information for seamless integration. Feel free to explore this and let us know if you have any questions or need further guidance!

#[account]
pub struct Coordinates {
    pub owner: Pubkey,
    pub x:i64,
    pub y:i64,
    pub color:[u8; 4],
    pub email:String,
    pub website:String,
    pub slogan:String,
    pub init_timestamp: i64,
    pub state:CoordinatesState,
    pub country:Country,
}

impl Coordinates {
    pub const MAX_SIZE: usize = 32+8+8+4+100+100+100+8+1;
}

#[derive(Clone, AnchorDeserialize, AnchorSerialize)]
pub struct ICoordinates(Coordinates);

impl ICoordinates {
    pub const LEN: usize = Coordinates::MAX_SIZE;
}

impl anchor_lang::AccountDeserialize for ICoordinates {
    fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
        Coordinates::try_deserialize(buf)
            .map(ICoordinates)
            .map_err(Into::into)
    }
}

impl anchor_lang::AccountSerialize for ICoordinates {}

impl anchor_lang::Owner for ICoordinates {
    fn owner() -> Pubkey {
        let addr = "2erNMjZig8yyLCqS3xiXBQLcSYK7yVib7AcZZTA44ekm";
        Pubkey::from_str(addr).unwrap()
    }
}

impl Deref for ICoordinates {
    type Target = Coordinates;

    fn deref(&self) -> &Self::Target {
        &self.0
    }
}

Purpose of the Code Snippets

The code snippets aim to facilitate the integration of the iCoordinates protocol with Solana's smart contract ecosystem. Specifically, they help in parsing account information related to coordinates and verifying the ownership of the account.

Explanation of Key Components

  1. Coordinates Structure:

    The Coordinates structure defines the account structure for storing coordinate information. It includes various fields like owner, x and y coordinates, color, email, website, and more.

  2. ICoordinates Structure:

    • ICoordinates is a wrapper struct around Coordinates and helps with serialization and deserialization for the Coordinates account.

  3. impl anchor_lang::AccountDeserialize for ICoordinates:

    This implementation allows deserialization of raw bytes into an ICoordinates instance, enabling easy access to the parsed account information.

  4. anchor_lang::AccountSerialize for ICoordinates:

    This implementation allows serialization of ICoordinates, aiding in storing account data on the blockchain.

  5. anchor_lang::Owner for ICoordinates:

    • anchor_lang::Owner trait is implemented to verify the ownership of the ICoordinates account.

    • The owner() function specifies the owner of the ICoordinates account, ensuring it's a Program Derived Address (PDA) from the iCoordinates program. 2erNMjZig8yyLCqS3xiXBQLcSYK7yVib7AcZZTA44ekm is the devNet address of iCoordinates program.

  6. Deref Implementation:

    • The Deref trait allows treating an ICoordinates instance as if it were a Coordinates instance.

    • It enables easy access to the fields and methods of Coordinates through an ICoordinates instance.

Overall Functionality

These components work together to ensure proper handling, serialization, and deserialization of coordinate-related account information. They also provide mechanisms to verify account ownership using PDAs associated with the iCoordinates program.

By using these constructs, the iCoordinates protocol can effectively manage and utilize account information related to coordinates on the Solana blockchain.

Integration with ICoordinates Account

use anchor_lang::prelude::*;
use crate::instructions::{ICoordinates};

#[derive(Accounts)]
pub struct IntegrateThirdPartyController<'info> {
    #[account(mut)]
    pub signer:Signer<'info>,
    pub coordinates: Account<'info, ICoordinates>,
    pub system_program:Program<'info,System>,
}

pub(crate) fn handler(ctx: Context<IntegrateThirdPartyController>) -> Result<()> {
    msg!("{}",ctx.accounts.coordinates.owner);
    msg!("{}",ctx.accounts.coordinates.website);
    msg!("{}",ctx.accounts.coordinates.email);
    Ok(())
}
  1. ICoordinates Structure:

    • The ICoordinates structure is designed to hold coordinate information, including owner, email, website, etc. It is a representation of the account structure in the Solana blockchain.

  2. Accessing Account Information:

    • In the IntegrateThirdPartyController struct, an account of type ICoordinates is passed in.

    • The handler function uses ctx.accounts.coordinates to access the ICoordinates account passed in as part of the context.

    • The msg! macro is used to print specific fields from the ICoordinates account, such as the owner, website, and email.

Summary

The provided code integrates with the ICoordinates account, allowing the program to parse and access coordinate information such as the owner, email, and website associated with a particular set of coordinates. This enables the program to utilize and display the coordinates' details within a third-party application.

Last updated