-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartContract.rs (Solana)
More file actions
48 lines (40 loc) · 1.35 KB
/
SmartContract.rs (Solana)
File metadata and controls
48 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// lib.rs (Solana Smart Contract)
use anchor_lang::prelude::*;
use std::str::FromStr;
#[program]
pub mod artwork_storage {
use super::*;
// Structure to store artwork details
pub fn upload_artwork(ctx: Context<UploadArtwork>, image_url: String, description: String) -> Result<()> {
let artwork = &mut ctx.accounts.artwork;
artwork.image_url = image_url;
artwork.description = description;
artwork.uploader = ctx.accounts.uploader.key();
artwork.timestamp = Clock::get()?.unix_timestamp;
Ok(())
}
// Function to fetch all uploaded artworks (Note: Solana doesn't support return of large data natively)
pub fn get_artworks(ctx: Context<GetArtworks>) -> Result<Vec<Artwork>> {
Ok(vec![]) // Placeholder: Solana smart contracts don't support complex return types directly
}
}
#[account]
pub struct Artwork {
pub image_url: String,
pub description: String,
pub uploader: Pubkey,
pub timestamp: i64,
}
#[derive(Accounts)]
pub struct UploadArtwork<'info> {
#[account(init, payer = uploader, space = 8 + 128 + 128 + 32 + 8)]
pub artwork: Account<'info, Artwork>,
#[account(mut)]
pub uploader: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
pub struct GetArtworks<'info> {
#[account(signer)]
pub user: AccountInfo<'info>,
}