generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating name and porting over solana-json.
- Loading branch information
1 parent
0fd8178
commit d58698d
Showing
88 changed files
with
5,341 additions
and
1,370 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
CARGO_TERM_COLOR=always | ||
NODE_VERSION=16.x | ||
PROGRAMS=["mpl-project-name"] | ||
PROGRAMS=["mpl-json"] | ||
RUST_VERSION=1.70.0 | ||
SOLANA_VERSION=1.16.18 |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rust-analyzer.linkedProjects": [ | ||
"./programs/mpl-json/Cargo.toml", | ||
] | ||
} |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,36 +1,22 @@ | ||
<h1 align="center"> | ||
Solana Project Template | ||
</h1> | ||
<p align="center"> | ||
A template for vanilla Solana programs and their clients. | ||
</p> | ||
<p align="center"> | ||
<img width="600" alt="Solana Project Template" src="https://github.com/metaplex-foundation/solana-project-template/assets/729235/aebf053a-d6fa-440b-9766-8957e843ec86" /> | ||
</p> | ||
<p align="center"> | ||
<a href="https://github.com/metaplex-foundation/solana-project-template/actions/workflows/main.yml"><img src="https://img.shields.io/github/actions/workflow/status/metaplex-foundation/solana-project-template/main.yml?logo=GitHub" /></a> | ||
</p> | ||
|
||
## Features | ||
|
||
- **Generate IDLs** using [Shank](https://github.com/metaplex-foundation/shank) | ||
- **Generate clients** for one or more programs using [Kinobi](https://github.com/metaplex-foundation/kinobi) | ||
- Configure **local validators** using [Amman](https://github.com/metaplex-foundation/amman) | ||
- **Build, test and lint** programs and clients using GitHub Actions. | ||
- **Publish** your [Umi](https://github.com/metaplex-foundation/umi) JavaScript client and its TypeScript documentation by dispatching a GitHub workflow. | ||
- **Publish** your Rust client SDK to [crates.io](https://crates.io) by dispatching a GitHub workflow. | ||
|
||
## Getting started | ||
|
||
1. [Use this template](https://github.com/new?template_name=solana-project-template&template_owner=metaplex-foundation) to create a new repository. | ||
2. Open the `init.sh` script and update the following variables. | ||
```sh | ||
NAME="mpl-project-name" | ||
DESCRIPTION="My project description" | ||
PUBLIC_KEY="MyProgram1111111111111111111111111111111111" | ||
``` | ||
3. Run the `init.sh` script to initialize the project. This will find/replace the variable above, rename some files/folders, update the README and, finally, remove the `init.sh` script. | ||
```sh | ||
./init.sh | ||
``` | ||
4. [Read the `CONTRIBUTING.md` file](./CONTRIBUTING.md) to learn more about how to use the project. | ||
# Mpl Json | ||
|
||
A simple program for writing JSON bytes on chain. | ||
|
||
## Programs | ||
|
||
This project contains the following programs: | ||
|
||
- [Mpl Json](./programs/mpl-json/README.md) `JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa` | ||
|
||
You will need a Rust version compatible with BPF to compile the program, currently we recommend using Rust 1.68.0. | ||
|
||
## Clients | ||
|
||
This project contains the following clients: | ||
|
||
- [JavaScript](./clients/js/README.md) | ||
- [Rust](./clients/rust/README.md) | ||
|
||
## Contributing | ||
|
||
Check out the [Contributing Guide](./CONTRIBUTING.md) the learn more about how to contribute to this project. |
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
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,186 @@ | ||
/** | ||
* 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 { | ||
Account, | ||
Context, | ||
Pda, | ||
PublicKey, | ||
RpcAccount, | ||
RpcGetAccountOptions, | ||
RpcGetAccountsOptions, | ||
assertAccountExists, | ||
deserializeAccount, | ||
gpaBuilder, | ||
publicKey as toPublicKey, | ||
} from '@metaplex-foundation/umi'; | ||
import { | ||
Serializer, | ||
array, | ||
bool, | ||
publicKey as publicKeySerializer, | ||
string, | ||
struct, | ||
u8, | ||
} from '@metaplex-foundation/umi/serializers'; | ||
import { Key, KeyArgs, getKeySerializer } from '../types'; | ||
|
||
export type JsonMetadata = Account<JsonMetadataAccountData>; | ||
|
||
export type JsonMetadataAccountData = { | ||
key: Key; | ||
bump: number; | ||
mutable: boolean; | ||
authorities: Array<PublicKey>; | ||
}; | ||
|
||
export type JsonMetadataAccountDataArgs = { | ||
key: KeyArgs; | ||
bump: number; | ||
mutable: boolean; | ||
authorities: Array<PublicKey>; | ||
}; | ||
|
||
export function getJsonMetadataAccountDataSerializer(): Serializer< | ||
JsonMetadataAccountDataArgs, | ||
JsonMetadataAccountData | ||
> { | ||
return struct<JsonMetadataAccountData>( | ||
[ | ||
['key', getKeySerializer()], | ||
['bump', u8()], | ||
['mutable', bool()], | ||
['authorities', array(publicKeySerializer())], | ||
], | ||
{ description: 'JsonMetadataAccountData' } | ||
) as Serializer<JsonMetadataAccountDataArgs, JsonMetadataAccountData>; | ||
} | ||
|
||
export function deserializeJsonMetadata(rawAccount: RpcAccount): JsonMetadata { | ||
return deserializeAccount(rawAccount, getJsonMetadataAccountDataSerializer()); | ||
} | ||
|
||
export async function fetchJsonMetadata( | ||
context: Pick<Context, 'rpc'>, | ||
publicKey: PublicKey | Pda, | ||
options?: RpcGetAccountOptions | ||
): Promise<JsonMetadata> { | ||
const maybeAccount = await context.rpc.getAccount( | ||
toPublicKey(publicKey, false), | ||
options | ||
); | ||
assertAccountExists(maybeAccount, 'JsonMetadata'); | ||
return deserializeJsonMetadata(maybeAccount); | ||
} | ||
|
||
export async function safeFetchJsonMetadata( | ||
context: Pick<Context, 'rpc'>, | ||
publicKey: PublicKey | Pda, | ||
options?: RpcGetAccountOptions | ||
): Promise<JsonMetadata | null> { | ||
const maybeAccount = await context.rpc.getAccount( | ||
toPublicKey(publicKey, false), | ||
options | ||
); | ||
return maybeAccount.exists ? deserializeJsonMetadata(maybeAccount) : null; | ||
} | ||
|
||
export async function fetchAllJsonMetadata( | ||
context: Pick<Context, 'rpc'>, | ||
publicKeys: Array<PublicKey | Pda>, | ||
options?: RpcGetAccountsOptions | ||
): Promise<JsonMetadata[]> { | ||
const maybeAccounts = await context.rpc.getAccounts( | ||
publicKeys.map((key) => toPublicKey(key, false)), | ||
options | ||
); | ||
return maybeAccounts.map((maybeAccount) => { | ||
assertAccountExists(maybeAccount, 'JsonMetadata'); | ||
return deserializeJsonMetadata(maybeAccount); | ||
}); | ||
} | ||
|
||
export async function safeFetchAllJsonMetadata( | ||
context: Pick<Context, 'rpc'>, | ||
publicKeys: Array<PublicKey | Pda>, | ||
options?: RpcGetAccountsOptions | ||
): Promise<JsonMetadata[]> { | ||
const maybeAccounts = await context.rpc.getAccounts( | ||
publicKeys.map((key) => toPublicKey(key, false)), | ||
options | ||
); | ||
return maybeAccounts | ||
.filter((maybeAccount) => maybeAccount.exists) | ||
.map((maybeAccount) => deserializeJsonMetadata(maybeAccount as RpcAccount)); | ||
} | ||
|
||
export function getJsonMetadataGpaBuilder( | ||
context: Pick<Context, 'rpc' | 'programs'> | ||
) { | ||
const programId = context.programs.getPublicKey( | ||
'mplJson', | ||
'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' | ||
); | ||
return gpaBuilder(context, programId) | ||
.registerFields<{ | ||
key: KeyArgs; | ||
bump: number; | ||
mutable: boolean; | ||
authorities: Array<PublicKey>; | ||
}>({ | ||
key: [0, getKeySerializer()], | ||
bump: [1, u8()], | ||
mutable: [2, bool()], | ||
authorities: [3, array(publicKeySerializer())], | ||
}) | ||
.deserializeUsing<JsonMetadata>((account) => | ||
deserializeJsonMetadata(account) | ||
); | ||
} | ||
|
||
export function findJsonMetadataPda( | ||
context: Pick<Context, 'eddsa' | 'programs'>, | ||
seeds: { | ||
/** The address of the JSON Account */ | ||
jsonAccount: PublicKey; | ||
} | ||
): Pda { | ||
const programId = context.programs.getPublicKey( | ||
'mplJson', | ||
'JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa' | ||
); | ||
return context.eddsa.findPda(programId, [ | ||
string({ size: 'variable' }).serialize('JSON'), | ||
publicKeySerializer().serialize(programId), | ||
publicKeySerializer().serialize(seeds.jsonAccount), | ||
]); | ||
} | ||
|
||
export async function fetchJsonMetadataFromSeeds( | ||
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>, | ||
seeds: Parameters<typeof findJsonMetadataPda>[1], | ||
options?: RpcGetAccountOptions | ||
): Promise<JsonMetadata> { | ||
return fetchJsonMetadata( | ||
context, | ||
findJsonMetadataPda(context, seeds), | ||
options | ||
); | ||
} | ||
|
||
export async function safeFetchJsonMetadataFromSeeds( | ||
context: Pick<Context, 'eddsa' | 'programs' | 'rpc'>, | ||
seeds: Parameters<typeof findJsonMetadataPda>[1], | ||
options?: RpcGetAccountOptions | ||
): Promise<JsonMetadata | null> { | ||
return safeFetchJsonMetadata( | ||
context, | ||
findJsonMetadataPda(context, seeds), | ||
options | ||
); | ||
} |
Oops, something went wrong.