Skip to content

Commit

Permalink
Merge pull request #161 from atonoy/refactoring/renamed-key-pair
Browse files Browse the repository at this point in the history
Refactoring/renamed key pair
  • Loading branch information
fukaoi authored Feb 21, 2023
2 parents fc294f6 + b172834 commit 1aa1122
Show file tree
Hide file tree
Showing 84 changed files with 347 additions and 369 deletions.
32 changes: 16 additions & 16 deletions examples/integration1-metaplex-nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//////////////////////////////////////////////

import assert from 'assert';
import { Airdrop, KeypairStr, Pubkey } from '@solana-suite/core';
import { Airdrop } from '@solana-suite/core';
import { Metaplex } from '@solana-suite/nft';
import { Node } from '@solana-suite/shared';
import { Node, KeypairAccount, Pubkey } from '@solana-suite/shared';
import { RandomAsset } from '../packages/storage/test/randomAsset';
import { requestTransferByKeypair } from './requestTransferByKeypair';

Expand All @@ -15,15 +15,15 @@ import { requestTransferByKeypair } from './requestTransferByKeypair';
//////////////////////////////////////////////

// create nft owner wallet.
const owner = KeypairStr.create();
const receipt = KeypairStr.create();
const feePayer = KeypairStr.create();
const owner = KeypairAccount.create();
const receipt = KeypairAccount.create();
const feePayer = KeypairAccount.create();

// faucet
// faucet
if (process.env.AIR_DROP) {
await Airdrop.request(feePayer.toPublicKey());
await Airdrop.request(feePayer.pubkey);
} else {
await requestTransferByKeypair(feePayer.toPublicKey());
await requestTransferByKeypair(feePayer.pubkey);
}

console.log('# owner: ', owner.pubkey);
Expand All @@ -49,8 +49,8 @@ import { requestTransferByKeypair } from './requestTransferByKeypair';
isMutable: true,
external_url: 'https://github.com/atonoy/solana-suite',
},
owner.toKeypair(),
feePayer.toKeypair()
owner.secret,
feePayer.secret
);

// this is NFT ID
Expand All @@ -66,7 +66,7 @@ import { requestTransferByKeypair } from './requestTransferByKeypair';
// Display metadata from blockchain(optional)
//////////////////////////////////////////////

const metadata = await Metaplex.findByOwner(owner.toPublicKey());
const metadata = await Metaplex.findByOwner(owner.pubkey);

metadata.match(
(value) => console.log('# metadata: ', value),
Expand All @@ -79,11 +79,11 @@ import { requestTransferByKeypair } from './requestTransferByKeypair';

//transfer nft owner => receipt
const inst2 = await Metaplex.transfer(
mint.toPublicKey(),
owner.toPublicKey(),
receipt.toPublicKey(),
[owner.toKeypair()],
feePayer.toKeypair()
mint,
owner.pubkey,
receipt.pubkey,
[owner.secret],
feePayer.secret
);

// submit instructions
Expand Down
44 changes: 17 additions & 27 deletions examples/integration2-transaction-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
//////////////////////////////////////////////

import assert from 'assert';
import {
SplToken,
Pubkey,
KeypairStr,
Airdrop,
DirectionFilter,
} from '@solana-suite/core';
import { SplToken, Airdrop, DirectionFilter } from '@solana-suite/core';

import { Node } from '@solana-suite/shared';
import { Node, Pubkey, KeypairAccount } from '@solana-suite/shared';
import { requestTransferByKeypair } from './requestTransferByKeypair';
import { RandomAsset } from '@solana-suite/storage/test/randomAsset';
import { StorageType } from '@solana-suite/shared-metaplex';
Expand All @@ -22,14 +16,14 @@ import { StorageType } from '@solana-suite/shared-metaplex';
//////////////////////////////////////////////

// create token owner wallet, receive token receipt wallet.
const owner = KeypairStr.create();
const receipt = KeypairStr.create();
const owner = KeypairAccount.create();
const receipt = KeypairAccount.create();

// faucet
if (process.env.AIR_DROP) {
await Airdrop.request(owner.toPublicKey());
await Airdrop.request(owner.pubkey);
} else {
await requestTransferByKeypair(owner.toPublicKey());
await requestTransferByKeypair(owner.pubkey);
}

console.log('# owner: ', owner);
Expand All @@ -51,8 +45,8 @@ import { StorageType } from '@solana-suite/shared-metaplex';
isMutable: false,
};
const inst1 = await SplToken.mint(
owner.toPublicKey(),
owner.toKeypair(),
owner.pubkey,
owner.secret,
totalAmount,
decimals,
tokenMetadata
Expand All @@ -74,10 +68,10 @@ import { StorageType } from '@solana-suite/shared-metaplex';

// transfer nft to receipt wallet
const inst2 = await SplToken.transfer(
mint.toPublicKey(),
owner.toPublicKey(),
receipt.toPublicKey(),
[owner.toKeypair()],
mint,
owner.pubkey,
receipt.pubkey,
[owner.secret],
10,
decimals
);
Expand All @@ -95,18 +89,14 @@ import { StorageType } from '@solana-suite/shared-metaplex';
//////////////////////////////////////////////

const hist1 = await SplToken.getHistory(
mint.toPublicKey(), // used mint
owner.toPublicKey() // search key
mint, // used mint
owner.pubkey // search key
);
console.log('# token history by publish: ', hist1.unwrap());

const hist2 = await SplToken.getHistory(
mint.toPublicKey(),
receipt.toPublicKey(),
{
directionFilter: DirectionFilter.Dest, // Dest or Source
}
);
const hist2 = await SplToken.getHistory(mint, receipt.pubkey, {
directionFilter: DirectionFilter.Dest, // Dest or Source
});
console.log(
'# token history result by destination filter : ',
hist2.unwrap()
Expand Down
8 changes: 4 additions & 4 deletions examples/integration3-handling-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const DEMO_ADDRESS = 'AorMYhBGmqo8Czp65WLjA42vKaQ5jS69gxyk6KxAsK3x';
//////////////////////////////////////////////
// Example1 type guard
//////////////////////////////////////////////
const ex1 = await SolNative.findByOwner(DEMO_ADDRESS.toPublicKey());
const ex1 = await SolNative.findByOwner(DEMO_ADDRESS);
ex1.isOk && console.log('# ex1: ', ex1.value);

if (ex1.isOk) {
Expand All @@ -29,14 +29,14 @@ const DEMO_ADDRESS = 'AorMYhBGmqo8Czp65WLjA42vKaQ5jS69gxyk6KxAsK3x';
//////////////////////////////////////////////
// Example2 unwrap
//////////////////////////////////////////////
const ex2 = await SolNative.findByOwner(DEMO_ADDRESS.toPublicKey());
const ex2 = await SolNative.findByOwner(DEMO_ADDRESS);
console.log('# ex2: ', ex2.unwrap());


//////////////////////////////////////////////
// Example3 map()
//////////////////////////////////////////////
const ex4 = await SolNative.findByOwner(DEMO_ADDRESS.toPublicKey());
const ex4 = await SolNative.findByOwner(DEMO_ADDRESS);

const mapped = ex4.map(
(value: SolNativeOwnerInfo) => value.sol * 100,
Expand All @@ -48,7 +48,7 @@ const DEMO_ADDRESS = 'AorMYhBGmqo8Czp65WLjA42vKaQ5jS69gxyk6KxAsK3x';
//////////////////////////////////////////////
// Example4 match()
//////////////////////////////////////////////
const ex5 = await SolNative.findByOwner(DEMO_ADDRESS.toPublicKey());
const ex5 = await SolNative.findByOwner(DEMO_ADDRESS);

ex5.match(
(value: SolNativeOwnerInfo) => console.log('# ex5: ', value),
Expand Down
25 changes: 10 additions & 15 deletions examples/integration4-multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
//////////////////////////////////////////////

import assert from 'assert';
import { KeypairStr, Multisig, Pubkey, Airdrop } from '@solana-suite/core';
import { Multisig, Airdrop } from '@solana-suite/core';

import { Node } from '@solana-suite/shared';
import { Node, KeypairAccount, Pubkey } from '@solana-suite/shared';
import { requestTransferByKeypair } from './requestTransferByKeypair';

(async () => {
Expand All @@ -19,18 +19,18 @@ import { requestTransferByKeypair } from './requestTransferByKeypair';
// publisher: mint token, transfer token and pay transaction fee account
// receipt: generally user account. sol not stocked

const feePayer = KeypairStr.create();
const feePayer = KeypairAccount.create();

// signer for multisig
const signer1 = KeypairStr.create();
const signer2 = KeypairStr.create();
const signer3 = KeypairStr.create();
const signer1 = KeypairAccount.create();
const signer2 = KeypairAccount.create();
const signer3 = KeypairAccount.create();

// faucet
if (process.env.AIR_DROP) {
await Airdrop.request(feePayer.toPublicKey());
await Airdrop.request(feePayer.pubkey);
} else {
await requestTransferByKeypair(feePayer.toPublicKey(), 0.6);
await requestTransferByKeypair(feePayer.pubkey, 0.6);
}

console.log('# feePayer: ', feePayer.pubkey);
Expand All @@ -41,13 +41,8 @@ import { requestTransferByKeypair } from './requestTransferByKeypair';
//////////////////////////////////////////////
// Setting multisig 2 of 2(m of n)
//////////////////////////////////////////////
const signerPubkeys = [
signer1.toPublicKey(),
signer2.toPublicKey(),
signer3.toPublicKey(),
];

const inst1 = await Multisig.create(2, feePayer.toKeypair(), signerPubkeys);
const signerPubkeys = [signer1.pubkey, signer2.pubkey, signer3.pubkey];
const inst1 = await Multisig.create(2, feePayer.secret, signerPubkeys);
const multisig = inst1.unwrap().data as Pubkey;
(await inst1.submit()).match(
async (value) => {
Expand Down
41 changes: 16 additions & 25 deletions examples/integration5-token-memo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
//////////////////////////////////////////////

import assert from 'assert';
import {
KeypairStr,
SplToken,
Pubkey,
Memo,
Airdrop,
} from '@solana-suite/core';

import { Node } from '@solana-suite/shared';
import { SplToken, Memo, Airdrop } from '@solana-suite/core';

import { Node, Pubkey, KeypairAccount } from '@solana-suite/shared';
import { requestTransferByKeypair } from './requestTransferByKeypair';
import { RandomAsset } from '@solana-suite/storage/test/randomAsset';
import { StorageType } from '@solana-suite/shared-metaplex';
Expand All @@ -22,14 +16,14 @@ import { StorageType } from '@solana-suite/shared-metaplex';
//////////////////////////////////////////////

// create token owner wallet, receive token receipt wallet.
const owner = KeypairStr.create();
const receipt = KeypairStr.create();
const owner = KeypairAccount.create();
const receipt = KeypairAccount.create();

// faucet
if (process.env.AIR_DROP) {
await Airdrop.request(owner.toPublicKey());
await Airdrop.request(owner.pubkey);
} else {
await requestTransferByKeypair(owner.toPublicKey());
await requestTransferByKeypair(owner.pubkey);
}

console.log('# owner: ', owner.pubkey);
Expand All @@ -52,8 +46,8 @@ import { StorageType } from '@solana-suite/shared-metaplex';
};

const inst1 = await SplToken.mint(
owner.toPublicKey(),
owner.toKeypair(),
owner.pubkey,
owner.secret,
totalAmount,
decimals,
tokenMetadata
Expand All @@ -76,8 +70,8 @@ import { StorageType } from '@solana-suite/shared-metaplex';
`;
const inst2 = Memo.create(
memoData,
receipt.toPublicKey(), // memo's owner
owner.toKeypair() // signer or feePayer
receipt.pubkey, // memo's owner
owner.secret // signer or feePayer
);

//////////////////////////////////////////////
Expand All @@ -86,10 +80,10 @@ import { StorageType } from '@solana-suite/shared-metaplex';

// transfer nft to receipt wallet
const inst3 = await SplToken.transfer(
mint.toPublicKey(),
owner.toPublicKey(),
receipt.toPublicKey(),
[owner.toKeypair()],
mint,
owner.pubkey,
receipt.pubkey,
[owner.secret],
10,
decimals
);
Expand All @@ -106,10 +100,7 @@ import { StorageType } from '@solana-suite/shared-metaplex';
// GET MEMO DATA
//////////////////////////////////////////////

const res = await SplToken.getHistory(
mint.toPublicKey(),
receipt.toPublicKey()
);
const res = await SplToken.getHistory(mint, receipt.pubkey);

res.isOk && console.log('# Transfer Memo: ', res.value[0].memo);
})();
Loading

0 comments on commit 1aa1122

Please sign in to comment.