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

implementing assets_by_* #163

Open
wants to merge 61 commits into
base: main2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
b884c87
feat(das_api): starting to implement get_assets_by_owner
stranzhay Jul 16, 2022
e3fbb0c
feat(das_api): starting to implement get_assets_by_owner
stranzhay Jul 16, 2022
5452feb
chore(digital_asset_types): changing branch
stranzhay Jul 18, 2022
3e9ed4b
Merge pull request #151 from stranzhay/stranzhay/implement-list-by
stranzhay Jul 19, 2022
aefd18e
feat(digital_asset_types): adding mock testing
Jul 19, 2022
81c3b6f
feat(digital_asset_types): building out testing continued
Jul 19, 2022
04fdd81
chore(digital_asset_types): remind unneeded code
stranzhay Jul 19, 2022
797dbb8
feat(digital_asset_types): creating mockdb setup functions
stranzhay Jul 20, 2022
38ce72d
refactor(digital_asset_types): refactor
stranzhay Jul 20, 2022
829f905
feat(digital_asset_types): finished testing setup for get asset by id
stranzhay Jul 20, 2022
a100bc8
feat(digital_asset_types): adding test get assets by owner
stranzhay Jul 21, 2022
7cd8202
feat(digital_asset_types): get assets by owner test working
stranzhay Jul 21, 2022
3533a50
feat(digital_asset_types): building out pagination
stranzhay Jul 22, 2022
b6455c9
feat(digital_asset_types): assets by owner ready for rpc testing
stranzhay Jul 25, 2022
096f5cd
chore(digital_asset_types): cleanup
stranzhay Jul 25, 2022
989f0c8
chore(digital_asset_types): cleanup
stranzhay Jul 25, 2022
299cdd5
chore(digital_asset_types): cleanup
stranzhay Jul 25, 2022
b3d02ea
Merge remote-tracking branch 'origin/main' into stranzhay/implement-l…
stranzhay Jul 25, 2022
3928755
feat(digital_asset_types): find assets by owners working with page ba…
stranzhay Jul 26, 2022
cc3bcf4
feat(digital_asset_types): adding cursor based pagination
stranzhay Jul 26, 2022
4ec32ae
Merge remote-tracking branch 'origin/main' into stranzhay/implement-l…
stranzhay Jul 26, 2022
dd709f6
chore: merge conflicts
stranzhay Jul 26, 2022
6e4731a
chore: merge conflicts
stranzhay Jul 26, 2022
e825c3c
chore: merge conflicts
stranzhay Jul 26, 2022
5dacfe2
Revert "chore: merge conflicts"
stranzhay Jul 26, 2022
db5194e
feat(digital_asset_types): cursor based pagination working
stranzhay Jul 26, 2022
cf37ea0
Merge branch 'stranzhay/cursor' into stranzhay/implement-list-by
stranzhay Jul 26, 2022
b69c2d1
feat(digital_asset_types): building out get assets by creators functi…
stranzhay Jul 28, 2022
7276bc2
chore: rpc tests working again
stranzhay Jul 29, 2022
74281be
chore: rpc tests working again
stranzhay Jul 29, 2022
45ecda4
chore: merge conflicts
stranzhay Jul 26, 2022
b84298f
chore: merge conflicts
stranzhay Jul 29, 2022
5def282
feat(digital_asset_types): building out get assets by creators functi…
stranzhay Jul 28, 2022
1946a0b
feat: get assets by creator working
stranzhay Jul 29, 2022
64899cd
chore: merge conflicts
stranzhay Jul 30, 2022
d6eac45
feat: get assets by creators working
stranzhay Jul 30, 2022
342edd4
chore: changing return type
stranzhay Jul 30, 2022
1fdae63
refactor: changing query to raw sql
stranzhay Jul 31, 2022
28156a6
chore: trying to make query faster
stranzhay Jul 31, 2022
544887f
feat: adding assets by group and listed assets by owner
stranzhay Aug 1, 2022
3f19a0f
feat: skeletoning other rpc methods
stranzhay Aug 1, 2022
cb4f2e0
chore: cleanup
stranzhay Aug 1, 2022
770431b
feat: finishing asset by group test
stranzhay Aug 1, 2022
1897bc9
chore: merge conflicts
stranzhay Aug 1, 2022
5961f1b
chore: add rpc http test for grouping
stranzhay Aug 1, 2022
6cc01c9
chore: merge wasn't successful
stranzhay Aug 1, 2022
200184b
chore: merge wasn't successful
stranzhay Aug 1, 2022
da57976
chore: merge wasn't successful
stranzhay Aug 1, 2022
b42f77c
chore: merge wasn't successful
stranzhay Aug 1, 2022
9ff092c
chore: merge wasn't successful
stranzhay Aug 1, 2022
87dbf19
chore: merge wasn't successful
stranzhay Aug 1, 2022
59f6bd1
chore: merge wasn't successful
stranzhay Aug 1, 2022
1c7a19f
chore: merge wasn't successful
stranzhay Aug 1, 2022
22c6699
chore: merge wasn't successful
stranzhay Aug 1, 2022
fb7f4eb
Merge branch 'stranzhay/implement-list-by' of https://github.com/jarr…
stranzhay Aug 1, 2022
bdbc7d5
feat: making test mock db code more modular
stranzhay Aug 1, 2022
18b1737
feat: making test mock db code more modular
stranzhay Aug 1, 2022
37850f0
chore: more code bad merge
stranzhay Aug 1, 2022
d2ddc12
chore: merge conflicts
stranzhay Aug 9, 2022
a6a96ff
chore: merge conflicts
stranzhay Aug 9, 2022
1b6dad7
chore: merge conflicts
stranzhay Aug 9, 2022
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
488 changes: 157 additions & 331 deletions Cargo.lock

Large diffs are not rendered by default.

66 changes: 43 additions & 23 deletions contracts/sdk/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,52 @@
import { PublicKey, TransactionInstruction, Transaction, Signer } from "@solana/web3.js";
import {
PublicKey,
TransactionInstruction,
Transaction,
Signer,
} from "@solana/web3.js";
import * as borsh from "borsh";
import { bignum } from "@metaplex-foundation/beet";
import { BN, Provider } from "@project-serum/anchor";

export const CANDY_WRAPPER_PROGRAM_ID = new PublicKey("WRAPYChf58WFCnyjXKJHtrPgzKXgHp6MD9aVDqJBbGh");
export const CANDY_WRAPPER_PROGRAM_ID = new PublicKey(
"WRAPYChf58WFCnyjXKJHtrPgzKXgHp6MD9aVDqJBbGh"
);

/// Wait for a transaction of a certain id to confirm and optionally log its messages
export async function logTx(provider: Provider, txId: string, verbose: boolean = true) {
export async function logTx(
provider: Provider,
txId: string,
verbose: boolean = true
) {
await provider.connection.confirmTransaction(txId, "confirmed");
if (verbose) {
console.log(

(await provider.connection.getConfirmedTransaction(txId, "confirmed"))!.meta!
.logMessages
(await provider.connection.getConfirmedTransaction(txId, "confirmed"))!
.meta!.logMessages
);
}
};
}

/// Execute a series of instructions in a txn
export async function execute(
provider: Provider,
instructions: TransactionInstruction[],
signers: Signer[],
skipPreflight: boolean = false,
verbose: boolean = false,
verbose: boolean = false
): Promise<string> {
let tx: Transaction = new Transaction();
instructions.map((ix) => { tx = tx.add(ix) });
instructions.map((ix) => {
tx = tx.add(ix);
});

let txid: string | null = null;
try {
txid = await provider.sendAndConfirm!(tx, signers, {
skipPreflight,
})
});
} catch (e) {
console.log("Tx error!", e.logs)
console.log("Tx error!", e.logs);
throw e;
}

Expand All @@ -44,8 +56,8 @@ export async function execute(

if (verbose) {
console.log(
(await provider.connection.getConfirmedTransaction(txid, "confirmed"))!.meta!
.logMessages
(await provider.connection.getConfirmedTransaction(txid, "confirmed"))!
.meta!.logMessages
);
}

Expand All @@ -68,7 +80,10 @@ export function val(num: bignum): BN {
/// Convert a string to a byte array, stored as an array of numbers
export function strToByteArray(str: string, padTo?: number): number[] {
let buf: Buffer = Buffer.from(
[...str].reduce((acc: number[], c, ind) => acc.concat([str.charCodeAt(ind)]), [])
[...str].reduce(
(acc: number[], c, ind) => acc.concat([str.charCodeAt(ind)]),
[]
)
);
if (padTo) {
buf = Buffer.concat([buf], padTo);
Expand All @@ -79,15 +94,18 @@ export function strToByteArray(str: string, padTo?: number): number[] {
/// Convert a string to a byte array, stored in a Uint8Array
export function strToByteUint8Array(str: string): Uint8Array {
return Uint8Array.from(
[...str].reduce((acc: number[], c, ind) => acc.concat([str.charCodeAt(ind)]), [])
[...str].reduce(
(acc: number[], c, ind) => acc.concat([str.charCodeAt(ind)]),
[]
)
);
}

/// Convert a 32 bit number to a buffer of bytes
export function num32ToBuffer(num: number) {
const isU32 = (num >= 0 && num < Math.pow(2, 32));
const isU32 = num >= 0 && num < Math.pow(2, 32);
if (!isU32) {
throw new Error("Attempted to convert non 32 bit integer to byte array")
throw new Error("Attempted to convert non 32 bit integer to byte array");
}
const b = Buffer.alloc(4);
b.writeInt32LE(num);
Expand All @@ -96,9 +114,9 @@ export function num32ToBuffer(num: number) {

/// Convert a 16 bit number to a buffer of bytes
export function num16ToBuffer(num: number) {
const isU16 = (num >= 0 && num < Math.pow(2, 16));
const isU16 = num >= 0 && num < Math.pow(2, 16);
if (!isU16) {
throw new Error("Attempted to convert non 16 bit integer to byte array")
throw new Error("Attempted to convert non 16 bit integer to byte array");
}
const b = Buffer.alloc(2);
b.writeUInt16LE(num);
Expand All @@ -107,10 +125,12 @@ export function num16ToBuffer(num: number) {

/// Check if two Array types contain the same values in order
export function arrayEquals(a: any[], b: any[]) {
return Array.isArray(a) &&
return (
Array.isArray(a) &&
Array.isArray(b) &&
a.length === b.length &&
a.every((val, index) => val === b[index]);
a.every((val, index) => val === b[index])
);
}

/// Convert Buffer to Uint8Array
Expand All @@ -124,5 +144,5 @@ export function bufferToArray(buffer: Buffer): number[] {

/// Remove null characters from a string. Useful for comparring byte-padded on-chain strings with off-chain values
export const trimStringPadding = (str: string): string => {
return str.replace(/\0/g, '')
}
return str.replace(/\0/g, "");
};
Loading