Skip to content

Commit

Permalink
Fix createGameAccount and join
Browse files Browse the repository at this point in the history
  • Loading branch information
Linerre committed Jan 17, 2025
1 parent bf0aef7 commit 9613caf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 99 deletions.
73 changes: 4 additions & 69 deletions js/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 19 additions & 19 deletions js/sdk-sui/bin/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import { CloseGameAccountParams, CreateGameAccountParams, CreatePlayerProfilePar
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
const wallet = new LocalSuiWallet('suiprivkey1qqds4vhlnm38pma946w5ke4g2846wpkgfygu88auscspswd5d4hl6fvc4q2');

const TEST_PACKAGE_ID = "0xf3c857da70fbf7275495e35243e66d628dcac3f7a83a4b094a918811df5b1f99";
const TEST_PACKAGE_ID = "0xa5698c13cdfc969501fc22982838d227cc83a79cf8810037d4b5e74451b569ea";
const TEST_GAME_ID = "0xe48c698837045e6296c7cd6d14d809f90192d38fb6651940d2adbaae2d700e1d";
const TEST_SERVER_TABLE_ID = "0x6b42f9a3c1be90700ca3ebca78ae3d65d360f3e17d52f17ca753cf185557b253";
const TEST_PROFILE_TABLE_ID = "0x0e93925793634d7aa2d6cf3fff73b171c5bf694f7616485cfee1773c58ff6f0e";
const TEST_RECIPIENT_ID = "0xc3c6277f5c374139e42d6972b5223e4b4bfbd4cabd7a5af6811af79301aefa66";
const TEST_REGISTRY = "0xc91df1896e7bfac9f288cdcd239c7aaf0e21a37bc38af4a5b006e066b368c0df";
const TEST_SERVER_TABLE_ID = "0xdac65117edba713a19b37dac5b7b0c6230eb2e16fc0e729d9fb6541282eca2b3";
const TEST_PROFILE_TABLE_ID = "0x4b4e744f568b7c904e4353f88f7c9a49a46f151493ff25878d9b0e66c2cd1ef3";
const TEST_RECIPIENT_ID = "0x3bd2cf3a28df3e80779b2e401af54ef24a405fdd7d67f7687145f597d18dbb03";
const TEST_REGISTRY_ID = "0xcb430f98bd97f8c3697cbdbf0de6b9b59411b2634aeebd07f4434fec30f443c7";
const TEST_GAME_NFT = "0x5ebed419309e71c1cd28a3249bbf792d2f2cc8b94b0e21e45a9873642c0a5cdc";

function testCreatePlayerProfile() {
Expand All @@ -32,15 +32,15 @@ async function testGetPlayerProfile() {
console.log('res', res)
}

function testCreateGameAccount() {
async function testCreateGameAccount() {
const suiTransport = new SuiTransport('https://fullnode.devnet.sui.io:443');
// console.log(wallet.walletAddr)
const params = {
title: 'yuumi Game', // title string
bundleAddr: TEST_GAME_NFT, // bundle_addr address params
owner: wallet.walletAddr, // owner address wallet
recipientAddr: randomPublicKey(), // recipient_addr address params
tokenAddr: "0x2", // token_addr address params "0x2"
tokenAddr: "0x2::sui::SUI", // token_addr address params "0x2"
maxPlayers: 6, // max_players u64 params
data_len: 2, // data_len u32 params
data: Uint8Array.from([1, 2]), // data vector<u8> params
Expand All @@ -49,22 +49,22 @@ function testCreateGameAccount() {
// minDeposit: BigInt(0),
// maxDeposit: BigInt(1000000)
// },
// entryType: {
// kind: 'ticket' as const,
// amount: BigInt(1000000)
// },
entryType: {
kind: 'ticket' as const,
amount: BigInt(100_000_000)
},
// entryType: {
// kind: 'gating' as const,
// collection: 'abc'
// },
entryType: {
kind: 'disabled' as const,
},
registrationAddr: '12',
// entryType: {
// kind: 'disabled' as const,
// },
registrationAddr: TEST_REGISTRY_ID,
}

let response = new ResponseHandle<CreateGameResponse, CreateGameError>()
suiTransport.createGameAccount(wallet, params, response);
let result = await suiTransport.createGameAccount(wallet, params, response);
console.log(response)
}

Expand Down Expand Up @@ -145,13 +145,13 @@ async function testRegisterGame() {

async function testJoinGame() {
const suiTransport = new SuiTransport('https://fullnode.devnet.sui.io:443');
const params: JoinGameParams = {
const params: JoinParams = {
gameAddr: TEST_GAME_ID,
amount: 100_000_000,
amount: BigInt(100_000_000),
position: 3,
verifyKey: 'player3',
};
let response = new ResponseHandle<RegisterGameResponse, RegisterGameError>();
let response = new ResponseHandle<JoinResponse, JoinError>();
let res = await suiTransport.join(wallet, params, response);
console.log('testJoinGame', response);
}
Expand Down
17 changes: 9 additions & 8 deletions js/sdk-sui/src/sui-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export class SuiTransport implements ITransport {
transaction.pure.string(params.title), // title string
transaction.pure.address(params.bundleAddr), // bundle_addr address params
transaction.pure.address(wallet.walletAddr), // owner address wallet

transaction.pure.address(recipientAddr), // recipient_addr address params
transaction.pure.string(params.tokenAddr), // token_addr address params "0x2"
transaction.pure.u16(params.maxPlayers), // max_players u64 params
Expand Down Expand Up @@ -88,6 +87,7 @@ export class SuiTransport implements ITransport {
transaction.moveCall({
target: `${PACKAGE_ID}::game::create_game`,
arguments: [...create_game_args, entry_type_result],
typeArguments: [params.tokenAddr]
});

const result = await wallet.send(transaction, suiClient, resp)
Expand Down Expand Up @@ -193,8 +193,12 @@ export class SuiTransport implements ITransport {
createProfileIfNeeded = false
} = params;

const suiClient = this.suiClient;
coerceWallet(wallet);

if (createProfileIfNeeded) {
await createPlayerProfile(wallet, { nick: wallet.addr.slice(0,8) });
let res = new ResponseHandle<CreatePlayerProfileResponse, CreatePlayerProfileError>;
await this.createPlayerProfile(wallet, { nick: 'RacePlayer' }, res);
}

// get game object for token info and object ref
Expand Down Expand Up @@ -225,14 +229,12 @@ export class SuiTransport implements ITransport {
if (!('initial_shared_version' in shared)) {
return resp.transactionFailed('game object is not shared')
}
const game_init_version = shared.initial_shared_verison;
const game_init_version = shared.initial_shared_version;

const transaction = new Transaction();
const suiClient = this.suiClient;
coerceWallet(wallet);

// split coin for buyin
const [coin] = transaction.splitCoin(transaction.gas, [transaction.pure(params.amount)]);
const [coin] = transaction.splitCoins(transaction.gas, [transaction.pure.u64(params.amount)]);
// join the game
transaction.moveCall({
target: `${PACKAGE_ID}::game::join_game`,
Expand All @@ -243,12 +245,11 @@ export class SuiTransport implements ITransport {
mutable: false,
}),
transaction.pure.u16(position),
transaction.pure.u64(access_version),
transaction.pure.u64(amount),
transaction.pure.u64(verifyKey),
coin
],
typeArgument: [game.tokenAddr]
typeArguments: [game.tokenAddr]
});

const result = await wallet.send(transaction, suiClient, resp);
Expand Down
5 changes: 2 additions & 3 deletions transport/src/sui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ impl TransportT for SuiTransport {
mutable: true
})?)?,
add_input(&mut ptb, new_pure_arg(&params.position)?)?,
add_input(&mut ptb, new_pure_arg(&params.access_version)?)?,
add_input(&mut ptb, new_pure_arg(&params.amount)?)?,
add_input(&mut ptb, new_pure_arg(&params.verify_key)?)?,
Argument::NestedResult(0, 0)
Expand Down Expand Up @@ -1550,10 +1549,10 @@ mod tests {
use super::*;

// temporary IDs for quick tests
const TEST_PACKAGE_ID: &str = "0xefdf5f95dd6dc87307e10b18abcafb35e0fdc82077c76edec18469064e4a4e99";
const TEST_PACKAGE_ID: &str = "0xa5698c13cdfc969501fc22982838d227cc83a79cf8810037d4b5e74451b569ea";
const TEST_GAME_ID: &str = "0xca42f1f255ea4d8944ce706bee318d9411d2f2a4ad043f29cc81aadf16f6a061";
const TEST_SERVER_TABLE_ID: &str = "0x302e13fa8331a2c37345ff053d347dd4e19666afa44ff62dcb6ec84fdc13a86e";
const TEST_PROFILE_TABLE_ID: &str = "0x4b4e744f568b7c904e4353f88f7c9a49a46f151493ff25878d9b0e66c2cd1ef3";
const TEST_PROFILE_TABLE_ID: &str = "0x302e13fa8331a2c37345ff053d347dd4e19666afa44ff62dcb6ec84fdc13a86e";
const TEST_RECIPIENT_ID: &str = "0x3bd2cf3a28df3e80779b2e401af54ef24a405fdd7d67f7687145f597d18dbb03";
const TEST_REGISTRY: &str = "0xcb430f98bd97f8c3697cbdbf0de6b9b59411b2634aeebd07f4434fec30f443c7";
const TEST_GAME_NFT: &str = "0x5ebed419309e71c1cd28a3249bbf792d2f2cc8b94b0e21e45a9873642c0a5cdc";
Expand Down

0 comments on commit 9613caf

Please sign in to comment.