-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use nitrate entrypoint * Add resize instruction * Add properties extension * Remove unused trait * Fix properties getter * Add bpf test * Update program interface * Add resize wrapper * Rename resize argument * Update kinobi config * Add bucket extension * Update generated code * Add test * Add boolean property type * Add test * Fix linting * Fix bridge test * Fix extension type * Fix bucket comments
- Loading branch information
Showing
14 changed files
with
226 additions
and
2 deletions.
There are no files selected for viewing
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,7 @@ | ||
import { TypedExtension } from '.'; | ||
import { ExtensionType } from '../generated'; | ||
|
||
export const bucket = (data: number[] | Uint8Array): TypedExtension => ({ | ||
type: ExtensionType.Bucket, | ||
data: data instanceof Uint8Array ? Array.from(data) : data, | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/** | ||
* This code was AUTOGENERATED using the kinobi library. | ||
* Please DO NOT EDIT THIS FILE, instead use visitors | ||
* to add features, then rerun kinobi to update it. | ||
* | ||
* @see https://github.com/metaplex-foundation/kinobi | ||
*/ | ||
|
||
import { | ||
Serializer, | ||
array, | ||
struct, | ||
u8, | ||
} from '@metaplex-foundation/umi/serializers'; | ||
|
||
export type Bucket = { data: Array<number> }; | ||
|
||
export type BucketArgs = Bucket; | ||
|
||
export function getBucketSerializer(): Serializer<BucketArgs, Bucket> { | ||
return struct<Bucket>([['data', array(u8(), { size: 'remainder' })]], { | ||
description: 'Bucket', | ||
}) as Serializer<BucketArgs, Bucket>; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { generateSigner } from '@metaplex-foundation/umi'; | ||
import test from 'ava'; | ||
import { | ||
Asset, | ||
Discriminator, | ||
ExtensionType, | ||
Standard, | ||
State, | ||
bucket, | ||
create, | ||
fetchAsset, | ||
initialize, | ||
} from '../../src'; | ||
import { createUmi } from '../_setup'; | ||
|
||
test('it can create a new asset with a bucket', async (t) => { | ||
// Given a Umi instance and a new signer. | ||
const umi = await createUmi(); | ||
const asset = generateSigner(umi); | ||
const owner = generateSigner(umi); | ||
|
||
// And we initialize an asset with a bucket extension. | ||
const response = await fetch( | ||
'https://arweave.net/Y8MBS8tqo9XJ_Z1l9V6BIMvhknWxhzP0UxSNBk1OXSs' | ||
); | ||
const data = new Uint8Array(await response.arrayBuffer()); | ||
|
||
// And we initialize a bucket extension. | ||
await initialize(umi, { | ||
asset, | ||
payer: umi.identity, | ||
extension: bucket(data), | ||
}).sendAndConfirm(umi); | ||
|
||
t.true(await umi.rpc.accountExists(asset.publicKey), 'asset exists'); | ||
|
||
// When we create the asset. | ||
await create(umi, { | ||
asset, | ||
owner: owner.publicKey, | ||
name: 'Bucket Asset', | ||
}).sendAndConfirm(umi); | ||
|
||
// Then an asset was created with the correct data. | ||
const assetAccount = await fetchAsset(umi, asset.publicKey); | ||
t.like(assetAccount, <Asset>{ | ||
discriminator: Discriminator.Asset, | ||
state: State.Unlocked, | ||
standard: Standard.NonFungible, | ||
owner: owner.publicKey, | ||
authority: umi.identity.publicKey, | ||
}); | ||
|
||
// And the bucket extension was added. | ||
const extension = assetAccount.extensions[0]; | ||
t.true(extension.type === ExtensionType.Bucket); | ||
|
||
// And the bucket has the correct data. | ||
if (extension.type === ExtensionType.Bucket) { | ||
t.is(extension.data.length, data.length); | ||
t.deepEqual(extension.data, Array.from(data)); | ||
} else { | ||
t.fail('extension is not a bucket'); | ||
} | ||
}); |
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,16 @@ | ||
//! This code was AUTOGENERATED using the kinobi library. | ||
//! Please DO NOT EDIT THIS FILE, instead use visitors | ||
//! to add features, then rerun kinobi to update it. | ||
//! | ||
//! [https://github.com/metaplex-foundation/kinobi] | ||
//! | ||
use borsh::BorshDeserialize; | ||
use borsh::BorshSerialize; | ||
use kaigan::types::RemainderVec; | ||
|
||
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] | ||
pub struct Bucket { | ||
pub data: RemainderVec<u8>, | ||
} |
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 |
---|---|---|
|
@@ -22,4 +22,5 @@ pub enum ExtensionType { | |
Manager, | ||
Proxy, | ||
Properties, | ||
Bucket, | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,5 @@ pub enum ExtensionType { | |
Manager, | ||
Proxy, | ||
Properties, | ||
Bucket, | ||
} |
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,79 @@ | ||
use std::ops::Deref; | ||
|
||
use super::{ExtensionBuilder, ExtensionData, ExtensionDataMut, ExtensionType, Lifecycle}; | ||
|
||
/// Extension to add binary data to an asset. | ||
#[repr(C)] | ||
pub struct Bucket<'a> { | ||
/// The raw data of the extension. | ||
pub data: &'a [u8], | ||
} | ||
|
||
impl<'a> ExtensionData<'a> for Bucket<'a> { | ||
const TYPE: ExtensionType = ExtensionType::Bucket; | ||
|
||
fn from_bytes(bytes: &'a [u8]) -> Self { | ||
Self { data: bytes } | ||
} | ||
|
||
fn length(&self) -> usize { | ||
self.data.len() | ||
} | ||
} | ||
|
||
pub struct BucketMut<'a> { | ||
/// The raw data of the extension. | ||
pub data: &'a mut [u8], | ||
} | ||
|
||
impl<'a> ExtensionDataMut<'a> for BucketMut<'a> { | ||
const TYPE: ExtensionType = ExtensionType::Bucket; | ||
|
||
fn from_bytes_mut(bytes: &'a mut [u8]) -> Self { | ||
Self { data: bytes } | ||
} | ||
} | ||
|
||
impl Lifecycle for BucketMut<'_> {} | ||
|
||
/// Builder for a `Bucket` extension. | ||
#[derive(Default)] | ||
pub struct BucketBuilder(Vec<u8>); | ||
|
||
impl BucketBuilder { | ||
pub fn with_capacity(capacity: usize) -> Self { | ||
Self(Vec::with_capacity(capacity)) | ||
} | ||
|
||
pub fn with_buffer(buffer: Vec<u8>) -> Self { | ||
Self(buffer) | ||
} | ||
|
||
/// Set the data of the bucket. | ||
pub fn set_data(&mut self, data: &[u8]) -> &mut Self { | ||
// setting the data replaces any existing data | ||
self.0.clear(); | ||
// add the data to the buffer | ||
self.0.extend_from_slice(data); | ||
|
||
self | ||
} | ||
} | ||
|
||
impl<'a> ExtensionBuilder<'a, Bucket<'a>> for BucketBuilder { | ||
fn build(&'a self) -> Bucket<'a> { | ||
Bucket::from_bytes(&self.0) | ||
} | ||
|
||
fn data(&mut self) -> Vec<u8> { | ||
std::mem::take(&mut self.0) | ||
} | ||
} | ||
|
||
impl Deref for BucketBuilder { | ||
type Target = Vec<u8>; | ||
|
||
fn deref(&self) -> &Self::Target { | ||
&self.0 | ||
} | ||
} |
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