Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add rust client sdk #41

Merged
merged 32 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/file-filters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ programs: &programs
client_common: &client_common
- *programs
- ".github/workflows/test-js.yml"
- ".github/workflows/test-sdk.yml"
- ".github/workflows/build-sdk.yml"
febo marked this conversation as resolved.
Show resolved Hide resolved
- ".github/workflows/main.yml"
- ".github/file-filters.yml"
- ".github/.env"
Expand All @@ -34,8 +36,13 @@ js_client: &js_client
- *client_common
- "clients/js/**"

rust_client: &rust_client
- *client_common
- "clients/rust/**"

clients: &clients
- *js_client
- *rust_client

# Any.

Expand Down
57 changes: 57 additions & 0 deletions .github/workflows/build-rust-client.yml
febo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build Rust Client

on:
workflow_call:
inputs:
rust:
type: string
solana:
type: string
workflow_dispatch:
inputs:
rust:
description: Rust version
default: 1.68.0
required: true
type: string
solana:
description: Solana version
default: 1.16.8
required: true
type: string

env:
CACHE: true

jobs:
build_sdk:
name: Build
runs-on: ubuntu-latest
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Load environment variables
run: cat .github/.env >> $GITHUB_ENV

- name: Install Rust
uses: metaplex-foundation/actions/install-rust@v1
with:
toolchain: ${{ inputs.rust || env.RUST_VERSION }}

- name: Install Solana
uses: metaplex-foundation/actions/install-solana@v1
with:
version: ${{ inputs.solana || env.SOLANA_VERSION }}
cache: ${{ env.CACHE }}

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --all-features --no-deps --manifest-path ./clients/rust/Cargo.toml

- name: Build SDK
shell: bash
working-directory: clients/rust
run: cargo build
19 changes: 17 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
js_changed: ${{ steps.changes.outputs.js_client }}
rust_changed: ${{ steps.changes.outputs.rust_client }}
permissions:
contents: write
steps:
Expand Down Expand Up @@ -98,9 +99,23 @@ jobs:
with:
filters: .github/file-filters.yml

test_js:
test_js_client:
if: needs.generate_clients.outputs.js_changed == 'true'
name: JS Client
needs: generate_clients
uses: ./.github/workflows/test-js.yml
uses: ./.github/workflows/test-js-client.yml
secrets: inherit

build_rust_client:
if: needs.generate_clients.outputs.rust_changed == 'true'
name: Rust Client
needs: generate_clients
uses: ./.github/workflows/build-rust-client.yml
secrets: inherit
febo marked this conversation as resolved.
Show resolved Hide resolved

test_rust_client:
if: needs.generate_clients.outputs.rust_changed == 'true'
name: Rust Client
needs: generate_clients
uses: ./.github/workflows/test-rust-client.yml
secrets: inherit
File renamed without changes.
42 changes: 42 additions & 0 deletions .github/workflows/test-rust-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Test Rust Client

on:
workflow_call:
inputs:
program_matrix:
type: string

env:
CACHE: true

jobs:
test_sdk:
name: Test
runs-on: ubuntu-latest-16-cores
steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Load environment variables
run: cat .github/.env >> $GITHUB_ENV

- name: Install Rust
uses: metaplex-foundation/actions/install-rust@v1
with:
toolchain: ${{ env.RUST_VERSION }}

- name: Install Solana
uses: metaplex-foundation/actions/install-solana@v1
with:
version: ${{ env.SOLANA_VERSION }}
cache: ${{ env.CACHE }}

- name: Download program builds
uses: actions/download-artifact@v3
with:
name: program-builds

- name: Run tests
shell: bash
working-directory: configs/program-scripts
run: RUST_LOG=error ./sdk.sh
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"rust-analyzer.linkedProjects": [
"./clients/rust/Cargo.toml",
"./programs/token-metadata/Cargo.toml",
]
}
5 changes: 3 additions & 2 deletions clients/js/src/generated/accounts/editionMarkerV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
publicKey as publicKeySerializer,
string,
struct,
u32,
} from '@metaplex-foundation/umi/serializers';
import { Key, KeyArgs, getKeySerializer } from '../types';

Expand All @@ -51,7 +52,7 @@ export function getEditionMarkerV2AccountDataSerializer(
return struct<EditionMarkerV2AccountData>(
[
['key', getKeySerializer()],
['ledger', bytes()],
['ledger', bytes({ size: u32() })],
],
{ description: 'EditionMarkerV2AccountData' }
) as Serializer<EditionMarkerV2AccountDataArgs, EditionMarkerV2AccountData>;
Expand Down Expand Up @@ -141,7 +142,7 @@ export function getEditionMarkerV2GpaBuilder(
return gpaBuilder(context, programId)
.registerFields<{ key: KeyArgs; ledger: Uint8Array }>({
key: [0, getKeySerializer()],
ledger: [1, bytes()],
ledger: [1, bytes({ size: u32() })],
})
.deserializeUsing<EditionMarkerV2>((account) =>
deserializeEditionMarkerV2(account)
Expand Down
febo marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export function approveCollectionAuthority(
collectionAuthorityRecord: [input.collectionAuthorityRecord, true] as const,
newCollectionAuthority: [input.newCollectionAuthority, false] as const,
mint: [input.mint, false] as const,
rent: [input.rent, false] as const,
};
addObjectProperty(
resolvedAccounts,
Expand Down Expand Up @@ -143,6 +142,11 @@ export function approveCollectionAuthority(
false,
] as const)
);
addObjectProperty(
resolvedAccounts,
'rent',
input.rent ? ([input.rent, false] as const) : ([programId, false] as const)
);

addAccountMeta(
keys,
Expand All @@ -156,7 +160,7 @@ export function approveCollectionAuthority(
addAccountMeta(keys, signers, resolvedAccounts.metadata, false);
addAccountMeta(keys, signers, resolvedAccounts.mint, false);
addAccountMeta(keys, signers, resolvedAccounts.systemProgram, false);
addAccountMeta(keys, signers, resolvedAccounts.rent, true);
addAccountMeta(keys, signers, resolvedAccounts.rent, false);

// Data.
const data =
Expand Down
8 changes: 6 additions & 2 deletions clients/js/src/generated/instructions/approveUseAuthority.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export function approveUseAuthority(
ownerTokenAccount: [input.ownerTokenAccount, true] as const,
mint: [input.mint, false] as const,
burner: [input.burner, false] as const,
rent: [input.rent, false] as const,
};
const resolvingArgs = {};
addObjectProperty(
Expand Down Expand Up @@ -171,6 +170,11 @@ export function approveUseAuthority(
false,
] as const)
);
addObjectProperty(
resolvedAccounts,
'rent',
input.rent ? ([input.rent, false] as const) : ([programId, false] as const)
);
const resolvedArgs = { ...input, ...resolvingArgs };

addAccountMeta(keys, signers, resolvedAccounts.useAuthorityRecord, false);
Expand All @@ -183,7 +187,7 @@ export function approveUseAuthority(
addAccountMeta(keys, signers, resolvedAccounts.burner, false);
addAccountMeta(keys, signers, resolvedAccounts.tokenProgram, false);
addAccountMeta(keys, signers, resolvedAccounts.systemProgram, false);
addAccountMeta(keys, signers, resolvedAccounts.rent, true);
addAccountMeta(keys, signers, resolvedAccounts.rent, false);

// Data.
const data =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
struct,
u8,
} from '@metaplex-foundation/umi/serializers';
import { addAccountMeta } from '../shared';
import { addAccountMeta, addObjectProperty } from '../shared';
import {
SetCollectionSizeArgs,
SetCollectionSizeArgsArgs,
Expand Down Expand Up @@ -113,12 +113,15 @@ export function bubblegumSetCollectionSize(
collectionAuthority: [input.collectionAuthority, true] as const,
collectionMint: [input.collectionMint, false] as const,
bubblegumSigner: [input.bubblegumSigner, false] as const,
collectionAuthorityRecord: [
input.collectionAuthorityRecord,
false,
] as const,
};
const resolvingArgs = {};
addObjectProperty(
resolvedAccounts,
'collectionAuthorityRecord',
input.collectionAuthorityRecord
? ([input.collectionAuthorityRecord, false] as const)
: ([programId, false] as const)
);
const resolvedArgs = { ...input, ...resolvingArgs };

addAccountMeta(keys, signers, resolvedAccounts.collectionMetadata, false);
Expand All @@ -129,7 +132,7 @@ export function bubblegumSetCollectionSize(
keys,
signers,
resolvedAccounts.collectionAuthorityRecord,
true
false
);

// Data.
Expand Down
10 changes: 8 additions & 2 deletions clients/js/src/generated/instructions/burnNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ export function burnNft(
mint: [input.mint, true] as const,
tokenAccount: [input.tokenAccount, true] as const,
masterEditionAccount: [input.masterEditionAccount, true] as const,
collectionMetadata: [input.collectionMetadata, true] as const,
};
addObjectProperty(
resolvedAccounts,
Expand All @@ -112,14 +111,21 @@ export function burnNft(
false,
] as const)
);
addObjectProperty(
resolvedAccounts,
'collectionMetadata',
input.collectionMetadata
? ([input.collectionMetadata, true] as const)
: ([programId, false] as const)
);

addAccountMeta(keys, signers, resolvedAccounts.metadata, false);
addAccountMeta(keys, signers, resolvedAccounts.owner, false);
addAccountMeta(keys, signers, resolvedAccounts.mint, false);
addAccountMeta(keys, signers, resolvedAccounts.tokenAccount, false);
addAccountMeta(keys, signers, resolvedAccounts.masterEditionAccount, false);
addAccountMeta(keys, signers, resolvedAccounts.splTokenProgram, false);
addAccountMeta(keys, signers, resolvedAccounts.collectionMetadata, true);
addAccountMeta(keys, signers, resolvedAccounts.collectionMetadata, false);

// Data.
const data = getBurnNftInstructionDataSerializer().serialize({});
Expand Down
10 changes: 8 additions & 2 deletions clients/js/src/generated/instructions/createEscrowAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export function createEscrowAccount(
escrow: [input.escrow, true] as const,
mint: [input.mint, false] as const,
tokenAccount: [input.tokenAccount, false] as const,
authority: [input.authority, false] as const,
};
addObjectProperty(
resolvedAccounts,
Expand Down Expand Up @@ -155,6 +154,13 @@ export function createEscrowAccount(
false,
] as const)
);
addObjectProperty(
resolvedAccounts,
'authority',
input.authority
? ([input.authority, false] as const)
: ([programId, false] as const)
);

addAccountMeta(keys, signers, resolvedAccounts.escrow, false);
addAccountMeta(keys, signers, resolvedAccounts.metadata, false);
Expand All @@ -164,7 +170,7 @@ export function createEscrowAccount(
addAccountMeta(keys, signers, resolvedAccounts.payer, false);
addAccountMeta(keys, signers, resolvedAccounts.systemProgram, false);
addAccountMeta(keys, signers, resolvedAccounts.sysvarInstructions, false);
addAccountMeta(keys, signers, resolvedAccounts.authority, true);
addAccountMeta(keys, signers, resolvedAccounts.authority, false);

// Data.
const data = getCreateEscrowAccountInstructionDataSerializer().serialize({});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export function createMasterEditionV3(
const resolvedAccounts = {
mint: [input.mint, true] as const,
mintAuthority: [input.mintAuthority, false] as const,
rent: [input.rent, false] as const,
};
const resolvingArgs = {};
addObjectProperty(
Expand Down Expand Up @@ -183,6 +182,11 @@ export function createMasterEditionV3(
false,
] as const)
);
addObjectProperty(
resolvedAccounts,
'rent',
input.rent ? ([input.rent, false] as const) : ([programId, false] as const)
);
const resolvedArgs = { ...input, ...resolvingArgs };

addAccountMeta(keys, signers, resolvedAccounts.edition, false);
Expand All @@ -193,7 +197,7 @@ export function createMasterEditionV3(
addAccountMeta(keys, signers, resolvedAccounts.metadata, false);
addAccountMeta(keys, signers, resolvedAccounts.tokenProgram, false);
addAccountMeta(keys, signers, resolvedAccounts.systemProgram, false);
addAccountMeta(keys, signers, resolvedAccounts.rent, true);
addAccountMeta(keys, signers, resolvedAccounts.rent, false);

// Data.
const data =
Expand Down
Loading