@block52/poker-vm-sdk 1.1.18 → 1.2.2

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
@@ -55862,6 +55862,7 @@ exports.NonPlayerActionType = void 0;
55862
55862
  (function (NonPlayerActionType) {
55863
55863
  NonPlayerActionType["DEAD_SMALL_BLIND"] = "dead-small-blind";
55864
55864
  NonPlayerActionType["DEAL"] = "deal";
55865
+ NonPlayerActionType["FORCE_CLOSE"] = "force-close";
55865
55866
  NonPlayerActionType["JOIN"] = "join";
55866
55867
  NonPlayerActionType["LEAVE"] = "leave";
55867
55868
  NonPlayerActionType["NEW_HAND"] = "new-hand";
@@ -57949,6 +57950,45 @@ class SigningCosmosClient extends CosmosClient {
57949
57950
  throw error;
57950
57951
  }
57951
57952
  }
57953
+ /**
57954
+ * Force-close a poker game and refund every seated player.
57955
+ *
57956
+ * Only the table creator can invoke this. Distinct from `deleteGame()`:
57957
+ * `deleteGame` requires zero players, this kicks everyone off and refunds
57958
+ * their stacks (plus any current-hand contribution and queued top-up) to
57959
+ * their wallet, then deletes the table.
57960
+ *
57961
+ * Cash format only. Chain rejects SNG/Tournament — those have separate
57962
+ * cancellation semantics (see block52/poker-vm#2173).
57963
+ */
57964
+ async forceCloseGame(gameId) {
57965
+ await this.initializeSigningClient();
57966
+ if (!this.signingClient || !this.wallet) {
57967
+ throw new Error("Signing client not initialized");
57968
+ }
57969
+ const [account] = await this.wallet.getAccounts();
57970
+ const creator = account.address;
57971
+ const msgForceCloseGame = {
57972
+ creator,
57973
+ gameId
57974
+ };
57975
+ const msg = {
57976
+ typeUrl: "/pokerchain.poker.v1.MsgForceCloseGame",
57977
+ value: msgForceCloseGame
57978
+ };
57979
+ const fee = gaslessFee();
57980
+ const memo = "Force-close poker game via SDK";
57981
+ console.log("🛑 Force-closing game:", { gameId });
57982
+ try {
57983
+ const result = await this.signingClient.signAndBroadcast(creator, [msg], fee, memo);
57984
+ console.log("✅ Force-close transaction successful:", result.transactionHash);
57985
+ return result.transactionHash;
57986
+ }
57987
+ catch (error) {
57988
+ console.error("❌ Force-close failed:", error);
57989
+ throw error;
57990
+ }
57991
+ }
57952
57992
  /**
57953
57993
  * Perform a game action (fold, call, raise, etc.)
57954
57994
  * The keeper calculates the action index automatically
@@ -57997,6 +58037,64 @@ class SigningCosmosClient extends CosmosClient {
57997
58037
  throw error;
57998
58038
  }
57999
58039
  }
58040
+ /**
58041
+ * Fast-path variant of {@link performAction}. Broadcasts in SYNC mode —
58042
+ * returns as soon as the tx passes CheckTx (mempool admission), without
58043
+ * waiting for block inclusion. Typical return latency is ~50–100ms vs
58044
+ * 5+ seconds for {@link performAction}.
58045
+ *
58046
+ * **The tx is NOT yet executed when this returns.** The caller MUST
58047
+ * reconcile authoritative state via the chain's WebSocket push, which
58048
+ * fires after block commit. Pair this with optimistic UI rendering
58049
+ * and a rollback path for the case where CheckTx succeeds but the
58050
+ * tx fails at DeliverTx (rare — illegal action that escaped local
58051
+ * validation, or block-time consensus surprises).
58052
+ *
58053
+ * Use cases:
58054
+ * - Frontend action submission where perceived latency matters.
58055
+ * - Any caller that has an independent path (WS, polling) to
58056
+ * learn the action's authoritative outcome.
58057
+ *
58058
+ * Do NOT use this for code paths that need the post-DeliverTx
58059
+ * `events` or `rawLog` — those are only populated by the BLOCK
58060
+ * variant. See block52/poker-vm#2104.
58061
+ *
58062
+ * Returns the tx hash on CheckTx success; throws if CheckTx
58063
+ * rejects (invalid signature, malformed msg, insufficient gas).
58064
+ */
58065
+ async performActionSync(gameId, action, amount = 0n, data) {
58066
+ await this.initializeSigningClient();
58067
+ if (!this.signingClient || !this.wallet) {
58068
+ throw new Error("Signing client not initialized");
58069
+ }
58070
+ const [account] = await this.wallet.getAccounts();
58071
+ const player = account.address;
58072
+ // Same msg shape as performAction — only the broadcast mode differs.
58073
+ const msgPerformAction = {
58074
+ player,
58075
+ gameId,
58076
+ action,
58077
+ amount: Long.fromString(amount.toString(), true),
58078
+ data: data || ""
58079
+ };
58080
+ const msg = {
58081
+ typeUrl: "/pokerchain.poker.v1.MsgPerformAction",
58082
+ value: msgPerformAction
58083
+ };
58084
+ const fee = gaslessFee();
58085
+ const memo = `Poker action (sync): ${action}`;
58086
+ try {
58087
+ // signAndBroadcastSync returns just the txhash, no DeliverTx
58088
+ // result. The caller waits on the WS push for the
58089
+ // authoritative outcome.
58090
+ const txHash = await this.signingClient.signAndBroadcastSync(player, [msg], fee, memo);
58091
+ return txHash;
58092
+ }
58093
+ catch (error) {
58094
+ console.error("❌ Action (sync) failed at CheckTx:", error);
58095
+ throw error;
58096
+ }
58097
+ }
58000
58098
  /**
58001
58099
  * Top up a player's stack at a table
58002
58100
  * The player must be seated at the table and have sufficient wallet balance.