Skip to content

Commit

Permalink
Updating name and porting over solana-json.
Browse files Browse the repository at this point in the history
  • Loading branch information
blockiosaurus committed Dec 2, 2023
1 parent 0fd8178 commit d58698d
Show file tree
Hide file tree
Showing 88 changed files with 5,341 additions and 1,370 deletions.
2 changes: 1 addition & 1 deletion .github/.env
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
6 changes: 3 additions & 3 deletions .github/file-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ program_common: &program_common
- ".github/file-filters.yml"
- ".github/.env"

mpl_project_name_program: &mpl_project_name_program
mpl_json: &mpl_json
- *program_common
- "programs/mpl-project-name/**"
- "programs/mpl-json/**"

programs: &programs
- *mpl_project_name_program
- *mpl_json

# Clients.

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-rust-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ jobs:
with:
name: rust-client-builds
# First wildcard ensures exported paths are consistently under the clients folder.
path: ./client*/rust/target/release/*mpl_project_name*
path: ./client*/rust/target/release/*mpl_json*
if-no-files-found: error
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ dist
.amman
.crates
.bin
JSoNoHBzUEFnjpZtcNcNzv5KLzo4tD5v4Z1pT9G4jJa.json
jsonz56LVLsegzJHJE5ysRC1qdeakiGFtB5ys8EWyJC.json
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"rust-analyzer.linkedProjects": [
"./programs/mpl-json/Cargo.toml",
]
}
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to Mpl Project Name
# Contributing to Mpl Json

This is a quick guide to help you contribute to Mpl Project Name.
This is a quick guide to help you contribute to Mpl Json.

## Getting started

Expand Down
22 changes: 0 additions & 22 deletions PROJECT_README.md

This file was deleted.

58 changes: 22 additions & 36 deletions README.md
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.
4 changes: 2 additions & 2 deletions clients/js/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing to the JavaScript client

This is a quick guide to help you contribute to the JavaScript client of Mpl Project Name.
This is a quick guide to help you contribute to the JavaScript client of Mpl Json.

## Getting started

Expand Down Expand Up @@ -49,7 +49,7 @@ To publish JavaScript clients using GitHub actions, we first need the following
Then, we'll need to create a new GitHub environment called `js-client-documentation` for the generated documentation of the JavaScript client. We can then select the `main` branch only and add the following secret variable to this specific environment.

- `VERCEL_PROJECT_ID` — The ID of the Vercel project you want to deploy to.
The convention for Metaplex is to create a new Vercel project named `mpl-project-name-js-docs` with the following deployment settings:
The convention for Metaplex is to create a new Vercel project named `mpl-json-js-docs` with the following deployment settings:

- Build Command: `pnpm run build:docs`
- Output Directory: `docs`
Expand Down
10 changes: 5 additions & 5 deletions clients/js/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# JavaScript client for Mpl Project Name
# JavaScript client for Mpl Json

A Umi-compatible JavaScript library for the project.

Expand All @@ -7,15 +7,15 @@ A Umi-compatible JavaScript library for the project.
1. First, if you're not already using Umi, [follow these instructions to install the Umi framework](https://github.com/metaplex-foundation/umi/blob/main/docs/installation.md).
2. Next, install this library using the package manager of your choice.
```sh
npm install @metaplex-foundation/mpl-project-name
npm install @metaplex-foundation/mpl-json
```
2. Finally, register the library with your Umi instance like so.
```ts
import { mplProjectName } from '@metaplex-foundation/mpl-project-name';
umi.use(mplProjectName());
import { mplJson } from '@metaplex-foundation/mpl-json';
umi.use(mplJson());
```

You can learn more about this library's API by reading its generated [TypeDoc documentation](https://mpl-project-name-js-docs.vercel.app).
You can learn more about this library's API by reading its generated [TypeDoc documentation](https://mpl-json-js-docs.vercel.app).

## Contributing

Expand Down
6 changes: 3 additions & 3 deletions clients/js/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "@metaplex-foundation/mpl-project-name",
"name": "@metaplex-foundation/mpl-json",
"version": "0.1.0",
"description": "My project description",
"description": "A simple program for writing JSON bytes on chain.",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"scripts": {
"build": "rimraf dist && tsc -p tsconfig.json",
"build:docs": "typedoc",
"test": "ava",
"test": "ava --timeout 60s",
"lint": "eslint --ext js,ts,tsx src",
"lint:fix": "eslint --fix --ext js,ts,tsx src",
"format": "prettier --check src test",
Expand Down
3 changes: 1 addition & 2 deletions clients/js/src/generated/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
* @see https://github.com/metaplex-foundation/kinobi
*/

export * from './myAccount';
export * from './myPdaAccount';
export * from './jsonMetadata';
186 changes: 186 additions & 0 deletions clients/js/src/generated/accounts/jsonMetadata.ts
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
);
}
Loading

0 comments on commit d58698d

Please sign in to comment.