@block52/poker-vm-sdk 1.2.7 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3242,7 +3242,7 @@ const MsgJoinGame = {
3242
3242
  },
3243
3243
  };
3244
3244
  function createBaseMsgLeaveGame() {
3245
- return { creator: "", gameId: "" };
3245
+ return { creator: "", gameId: "", finishingOrder: [] };
3246
3246
  }
3247
3247
  const MsgLeaveGame = {
3248
3248
  encode(message, writer = new BinaryWriter()) {
@@ -3252,6 +3252,9 @@ const MsgLeaveGame = {
3252
3252
  if (message.gameId !== "") {
3253
3253
  writer.uint32(18).string(message.gameId);
3254
3254
  }
3255
+ for (const v of message.finishingOrder) {
3256
+ writer.uint32(26).string(v);
3257
+ }
3255
3258
  return writer;
3256
3259
  },
3257
3260
  decode(input, length) {
@@ -3275,6 +3278,13 @@ const MsgLeaveGame = {
3275
3278
  message.gameId = reader.string();
3276
3279
  continue;
3277
3280
  }
3281
+ case 3: {
3282
+ if (tag !== 26) {
3283
+ break;
3284
+ }
3285
+ message.finishingOrder.push(reader.string());
3286
+ continue;
3287
+ }
3278
3288
  }
3279
3289
  if ((tag & 7) === 4 || tag === 0) {
3280
3290
  break;
@@ -3287,6 +3297,9 @@ const MsgLeaveGame = {
3287
3297
  return {
3288
3298
  creator: isSet$2b(object.creator) ? globalThis.String(object.creator) : "",
3289
3299
  gameId: isSet$2b(object.gameId) ? globalThis.String(object.gameId) : "",
3300
+ finishingOrder: globalThis.Array.isArray(object?.finishingOrder)
3301
+ ? object.finishingOrder.map((e) => globalThis.String(e))
3302
+ : [],
3290
3303
  };
3291
3304
  },
3292
3305
  toJSON(message) {
@@ -3297,6 +3310,9 @@ const MsgLeaveGame = {
3297
3310
  if (message.gameId !== "") {
3298
3311
  obj.gameId = message.gameId;
3299
3312
  }
3313
+ if (message.finishingOrder?.length) {
3314
+ obj.finishingOrder = message.finishingOrder;
3315
+ }
3300
3316
  return obj;
3301
3317
  },
3302
3318
  create(base) {
@@ -3306,6 +3322,7 @@ const MsgLeaveGame = {
3306
3322
  const message = createBaseMsgLeaveGame();
3307
3323
  message.creator = object.creator ?? "";
3308
3324
  message.gameId = object.gameId ?? "";
3325
+ message.finishingOrder = object.finishingOrder?.map((e) => e) || [];
3309
3326
  return message;
3310
3327
  },
3311
3328
  };
@@ -61197,6 +61214,103 @@ class SigningCosmosClient extends CosmosClient {
61197
61214
  const base64 = encoding.toBase64(txExports.TxRaw.encode(txRaw).finish());
61198
61215
  return { base64, sequence: explicit.sequence, accountNumber: explicit.accountNumber };
61199
61216
  }
61217
+ /**
61218
+ * Resolves the signer data (account number + sequence + chain id) for a
61219
+ * sign-only message: uses the caller-supplied data when present (the
61220
+ * gateway settlement path tracks sequence locally so optimistic actions
61221
+ * don't query the stale committed value), else queries the account once.
61222
+ */
61223
+ async resolveSignerData(player, signerData) {
61224
+ if (signerData) {
61225
+ return signerData;
61226
+ }
61227
+ const accountInfo = await this.getAccount(player);
61228
+ return {
61229
+ accountNumber: Number(accountInfo.account.account_number),
61230
+ sequence: Number(accountInfo.account.sequence),
61231
+ chainId: this.config.chainId
61232
+ };
61233
+ }
61234
+ /**
61235
+ * Signs a single cosmos message (no broadcast) and returns the base64 TxRaw
61236
+ * plus the signer data used — the sign-only primitive the money-mover
61237
+ * helpers below share with signPerformAction's gateway-settlement pattern.
61238
+ */
61239
+ async signMsgOnly(msg, memo, signerData) {
61240
+ await this.initializeSigningClient();
61241
+ if (!this.signingClient || !this.wallet) {
61242
+ throw new Error("Signing client not initialized");
61243
+ }
61244
+ const [account] = await this.wallet.getAccounts();
61245
+ const player = account.address;
61246
+ const explicit = await this.resolveSignerData(player, signerData);
61247
+ const txRaw = await this.signingClient.sign(player, [msg], gaslessFee(), memo, explicit);
61248
+ const base64 = encoding.toBase64(txExports.TxRaw.encode(txRaw).finish());
61249
+ return { base64, sequence: explicit.sequence, accountNumber: explicit.accountNumber };
61250
+ }
61251
+ /**
61252
+ * Sign-only MsgJoinGame: builds and signs the player's buy-in tx WITHOUT
61253
+ * broadcasting, returning the base64 TxRaw for the gateway to relay
61254
+ * (WS-first money-mover settlement, block52/poker-vm#2325). The player is
61255
+ * the signer — the gateway never moves funds on their behalf. Mirrors
61256
+ * joinGame()'s message shape and signPerformAction()'s sign-only return.
61257
+ */
61258
+ async signJoinGame(gameId, seat, buyInAmount, signerData) {
61259
+ await this.initializeSigningClient();
61260
+ const [account] = await this.wallet.getAccounts();
61261
+ const msg = {
61262
+ typeUrl: "/pokerchain.poker.v1.MsgJoinGame",
61263
+ value: {
61264
+ player: account.address,
61265
+ gameId,
61266
+ seat: Long.fromNumber(seat, true),
61267
+ buyInAmount: Long.fromString(buyInAmount.toString(), true)
61268
+ }
61269
+ };
61270
+ return this.signMsgOnly(msg, "Join poker game (relay)", signerData);
61271
+ }
61272
+ /**
61273
+ * Sign-only MsgLeaveGame (no broadcast). For cash games and SNGs the chain
61274
+ * already finalized, the chain decides the refund from its own state and
61275
+ * the message carries only {creator, gameId}. (#2325)
61276
+ *
61277
+ * For an SNG that finalized off-chain (WS-first money-movers — the gateway
61278
+ * never relays the tournament-ending gameplay action, so the chain's
61279
+ * Results are empty), pass `finishingOrder`: the place-1-first list of
61280
+ * player addresses. The chain validates the ordering and recomputes the
61281
+ * payouts from its own prize-pool math — this message supplies only the
61282
+ * ORDER, never any amount. (pokerchain#229)
61283
+ */
61284
+ async signLeaveGame(gameId, signerData, finishingOrder = []) {
61285
+ await this.initializeSigningClient();
61286
+ const [account] = await this.wallet.getAccounts();
61287
+ const msg = {
61288
+ typeUrl: "/pokerchain.poker.v1.MsgLeaveGame",
61289
+ value: {
61290
+ creator: account.address,
61291
+ gameId,
61292
+ finishingOrder
61293
+ }
61294
+ };
61295
+ return this.signMsgOnly(msg, "Leave poker game (relay)", signerData);
61296
+ }
61297
+ /**
61298
+ * Sign-only MsgTopUp (no broadcast) — escrow deposit added to the player's
61299
+ * stack; gateway relays it after PVM-verifying the optimistic apply. (#2325)
61300
+ */
61301
+ async signTopUp(gameId, amount, signerData) {
61302
+ await this.initializeSigningClient();
61303
+ const [account] = await this.wallet.getAccounts();
61304
+ const msg = {
61305
+ typeUrl: "/pokerchain.poker.v1.MsgTopUp",
61306
+ value: {
61307
+ player: account.address,
61308
+ gameId,
61309
+ amount: Long.fromString(amount.toString(), true)
61310
+ }
61311
+ };
61312
+ return this.signMsgOnly(msg, "Top up poker stack (relay)", signerData);
61313
+ }
61200
61314
  /**
61201
61315
  * Top up a player's stack at a table
61202
61316
  * The player must be seated at the table and have sufficient wallet balance.