diff --git a/package-lock.json b/package-lock.json index 35eef3738..f94d4572e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19691,7 +19691,7 @@ }, "packages/fcl": { "name": "@onflow/fcl", - "version": "1.8.1", + "version": "1.9.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6", @@ -19777,7 +19777,7 @@ }, "packages/fcl-wc": { "name": "@onflow/fcl-wc", - "version": "5.0.1", + "version": "6.0.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.9", @@ -19795,7 +19795,7 @@ "jest": "^29.5.0" }, "peerDependencies": { - "@onflow/fcl": "^1.8.1" + "@onflow/fcl": "^1.9.0" } }, "packages/fcl/node_modules/eslint-plugin-jsdoc": { @@ -20589,7 +20589,7 @@ }, "packages/transport-http": { "name": "@onflow/transport-http", - "version": "1.8.1", + "version": "1.9.0", "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.18.6", diff --git a/packages/sdk/src/build/build-authorizations.js b/packages/sdk/src/build/build-authorizations.js index 40aeb53b0..ae1ee0a8b 100644 --- a/packages/sdk/src/build/build-authorizations.js +++ b/packages/sdk/src/build/build-authorizations.js @@ -1,9 +1,10 @@ -import {pipe, prepAccount, AUTHORIZER} from "../interaction/interaction" +import { TransactionRole } from "@onflow/typedefs" +import {pipe, prepAccount} from "../interaction/interaction" export function authorizations(ax = []) { return pipe( ax.map(authz => { - return prepAccount(authz, {role: AUTHORIZER}) + return prepAccount(authz, {role: TransactionRole.AUTHORIZER}) }) ) } diff --git a/packages/sdk/src/build/build-payer.js b/packages/sdk/src/build/build-payer.js index e791af322..bb16d233c 100644 --- a/packages/sdk/src/build/build-payer.js +++ b/packages/sdk/src/build/build-payer.js @@ -1,10 +1,11 @@ -import {pipe, prepAccount, PAYER} from "../interaction/interaction" +import { TransactionRole } from "@onflow/typedefs" +import {pipe, prepAccount} from "../interaction/interaction" export function payer(ax = []) { if (!Array.isArray(ax)) ax = [ax] return pipe( ax.map(authz => { - return prepAccount(authz, {role: PAYER}) + return prepAccount(authz, {role: TransactionRole.PAYER}) }) ) } diff --git a/packages/sdk/src/build/build-proposer.js b/packages/sdk/src/build/build-proposer.js index aabbb9180..c05608fca 100644 --- a/packages/sdk/src/build/build-proposer.js +++ b/packages/sdk/src/build/build-proposer.js @@ -1,5 +1,6 @@ -import {prepAccount, PROPOSER} from "../interaction/interaction" +import { TransactionRole } from "@onflow/typedefs" +import {prepAccount} from "../interaction/interaction" export async function proposer(authz) { - return prepAccount(authz, {role: PROPOSER}) + return prepAccount(authz, {role: TransactionRole.PROPOSER}) } diff --git a/packages/sdk/src/interaction/interaction.ts b/packages/sdk/src/interaction/interaction.ts index 24c2c6ee4..c35e0f380 100644 --- a/packages/sdk/src/interaction/interaction.ts +++ b/packages/sdk/src/interaction/interaction.ts @@ -2,13 +2,13 @@ import {invariant} from "@onflow/util-invariant" import {v4 as uuidv4} from "uuid" import {log, LEVELS} from "@onflow/util-logger" -import { InteractionAccount, ACCOUNT, PARAM, ARGUMENT, UNKNOWN, OK, Interaction, AUTHORIZER, PAYER, SCRIPT, TRANSACTION, GET_TRANSACTION_STATUS, GET_TRANSACTION, GET_ACCOUNT, GET_EVENTS, PING, GET_BLOCK, GET_BLOCK_HEADER, GET_COLLECTION, GET_NETWORK_PARAMETERS, BAD, PROPOSER } from "@onflow/typedefs"; +import { TransactionRole, Interaction, InteractionAccount, InteractionResolverKind, InteractionStatus, InteractionTag } from "@onflow/typedefs"; type AcctFn = (acct: InteractionAccount) => InteractionAccount; type AccountFn = AcctFn & Partial; const ACCT = `{ - "kind":"${ACCOUNT}", + "kind":"${InteractionResolverKind.ACCOUNT}", "tempId":null, "addr":null, "keyId":null, @@ -24,18 +24,8 @@ const ACCT = `{ } }` -const PRM = `{ - "kind":"${PARAM}", - "tempId":null, - "key":null, - "value":null, - "asParam":null, - "xform":null, - "resolve": null -}` - const ARG = `{ - "kind":"${ARGUMENT}", + "kind":"${InteractionResolverKind.ARGUMENT}", "tempId":null, "value":null, "asArgument":null, @@ -45,9 +35,9 @@ const ARG = `{ }` const IX = `{ - "tag":"${UNKNOWN}", + "tag":"${InteractionTag.UNKNOWN}", "assigns":{}, - "status":"${OK}", + "status":"${InteractionStatus.OK}", "reason":null, "accounts":{}, "params":{}, @@ -118,17 +108,17 @@ export const isInteraction = (ix: Interaction) => { } export const Ok = (ix: Interaction) => { - ix.status = OK + ix.status = InteractionStatus.OK return ix } export const Bad = (ix: Interaction, reason: string) => { - ix.status = BAD + ix.status = InteractionStatus.BAD ix.reason = reason return ix } -const makeIx = (wat: string) => (ix: Interaction) => { +const makeIx = (wat: InteractionTag) => (ix: Interaction) => { ix.tag = wat return Ok(ix) } @@ -145,7 +135,7 @@ const prepAccountKeyId = (acct: Partial | AccountFn): Partia } interface IPrepAccountOpts { - role?: typeof AUTHORIZER | typeof PAYER | typeof PROPOSER | null + role?: TransactionRole | null } export const initAccount = (): InteractionAccount => JSON.parse(ACCT) @@ -187,9 +177,9 @@ export const prepAccount = (acct: InteractionAccount | AccountFn, opts: IPrepAcc }, } - if (role === AUTHORIZER) { + if (role === TransactionRole.AUTHORIZER) { ix.authorizations.push(tempId) - } else if (role === PAYER) { + } else if (role === TransactionRole.PAYER) { ix.payer.push(tempId) } else if (role) { ix[role] = tempId @@ -215,41 +205,40 @@ export const makeArgument = (arg: Record) => (ix: Interaction) => return Ok(ix) } -export const makeUnknown /* */ = makeIx(UNKNOWN) -export const makeScript /* */ = makeIx(SCRIPT) -export const makeTransaction /* */ = makeIx(TRANSACTION) -export const makeGetTransactionStatus /* */ = makeIx(GET_TRANSACTION_STATUS) -export const makeGetTransaction /* */ = makeIx(GET_TRANSACTION) -export const makeGetAccount /* */ = makeIx(GET_ACCOUNT) -export const makeGetEvents /* */ = makeIx(GET_EVENTS) -export const makePing /* */ = makeIx(PING) -export const makeGetBlock /* */ = makeIx(GET_BLOCK) -export const makeGetBlockHeader /* */ = makeIx(GET_BLOCK_HEADER) -export const makeGetCollection /* */ = makeIx(GET_COLLECTION) -export const makeGetNetworkParameters /* */ = makeIx(GET_NETWORK_PARAMETERS) - -const is = (wat: string) => (ix: Interaction) => ix.tag === wat - -export const isUnknown /* */ = is(UNKNOWN) -export const isScript /* */ = is(SCRIPT) -export const isTransaction /* */ = is(TRANSACTION) -export const isGetTransactionStatus /* */ = is(GET_TRANSACTION_STATUS) -export const isGetTransaction /* */ = is(GET_TRANSACTION) -export const isGetAccount /* */ = is(GET_ACCOUNT) -export const isGetEvents /* */ = is(GET_EVENTS) -export const isPing /* */ = is(PING) -export const isGetBlock /* */ = is(GET_BLOCK) -export const isGetBlockHeader /* */ = is(GET_BLOCK_HEADER) -export const isGetCollection /* */ = is(GET_COLLECTION) -export const isGetNetworkParameters /* */ = is(GET_NETWORK_PARAMETERS) - -export const isOk /* */ = (ix: Interaction) => ix.status === OK -export const isBad /* */ = (ix: Interaction) => ix.status === BAD +export const makeUnknown /* */ = makeIx(InteractionTag.UNKNOWN) +export const makeScript /* */ = makeIx(InteractionTag.SCRIPT) +export const makeTransaction /* */ = makeIx(InteractionTag.TRANSACTION) +export const makeGetTransactionStatus /* */ = makeIx(InteractionTag.GET_TRANSACTION_STATUS) +export const makeGetTransaction /* */ = makeIx(InteractionTag.GET_TRANSACTION) +export const makeGetAccount /* */ = makeIx(InteractionTag.GET_ACCOUNT) +export const makeGetEvents /* */ = makeIx(InteractionTag.GET_EVENTS) +export const makePing /* */ = makeIx(InteractionTag.PING) +export const makeGetBlock /* */ = makeIx(InteractionTag.GET_BLOCK) +export const makeGetBlockHeader /* */ = makeIx(InteractionTag.GET_BLOCK_HEADER) +export const makeGetCollection /* */ = makeIx(InteractionTag.GET_COLLECTION) +export const makeGetNetworkParameters /* */ = makeIx(InteractionTag.GET_NETWORK_PARAMETERS) + +const is = (wat: InteractionTag) => (ix: Interaction) => ix.tag === wat + +export const isUnknown /* */ = is(InteractionTag.UNKNOWN) +export const isScript /* */ = is(InteractionTag.SCRIPT) +export const isTransaction /* */ = is(InteractionTag.TRANSACTION) +export const isGetTransactionStatus /* */ = is(InteractionTag.GET_TRANSACTION_STATUS) +export const isGetTransaction /* */ = is(InteractionTag.GET_TRANSACTION) +export const isGetAccount /* */ = is(InteractionTag.GET_ACCOUNT) +export const isGetEvents /* */ = is(InteractionTag.GET_EVENTS) +export const isPing /* */ = is(InteractionTag.PING) +export const isGetBlock /* */ = is(InteractionTag.GET_BLOCK) +export const isGetBlockHeader /* */ = is(InteractionTag.GET_BLOCK_HEADER) +export const isGetCollection /* */ = is(InteractionTag.GET_COLLECTION) +export const isGetNetworkParameters /* */ = is(InteractionTag.GET_NETWORK_PARAMETERS) + +export const isOk /* */ = (ix: Interaction) => ix.status === InteractionStatus.OK +export const isBad /* */ = (ix: Interaction) => ix.status === InteractionStatus.BAD export const why /* */ = (ix: Interaction) => ix.reason -export const isAccount /* */ = (account: Record) => account.kind === ACCOUNT -export const isParam /* */ = (param: Record) => param.kind === PARAM -export const isArgument /* */ = (argument: Record) => argument.kind === ARGUMENT +export const isAccount /* */ = (account: Record) => account.kind === InteractionResolverKind.ACCOUNT +export const isArgument /* */ = (argument: Record) => argument.kind === InteractionResolverKind.ARGUMENT const hardMode = (ix: Interaction) => { for (let key of Object.keys(ix)) { @@ -300,6 +289,4 @@ export const update = (key: string, fn = identity) => (ix: Interaction) => { export const destroy = (key: string) => (ix: Interaction) => { delete ix.assigns[key] return Ok(ix) -} - -export * from "@onflow/typedefs" +} \ No newline at end of file diff --git a/packages/typedefs/src/interaction.ts b/packages/typedefs/src/interaction.ts index df01c5d6f..255ab74ed 100644 --- a/packages/typedefs/src/interaction.ts +++ b/packages/typedefs/src/interaction.ts @@ -1,85 +1,91 @@ +export enum InteractionTag { + UNKNOWN = "UNKNOWN", + SCRIPT = "SCRIPT", + TRANSACTION = "TRANSACTION", + GET_TRANSACTION_STATUS = "GET_TRANSACTION_STATUS", + GET_ACCOUNT = "GET_ACCOUNT", + GET_EVENTS = "GET_EVENTS", + PING = "PING", + GET_TRANSACTION = "GET_TRANSACTION", + GET_BLOCK = "GET_BLOCK", + GET_BLOCK_HEADER = "GET_BLOCK_HEADER", + GET_COLLECTION = "GET_COLLECTION", + GET_NETWORK_PARAMETERS = "GET_NETWORK_PARAMETERS", +} -export const UNKNOWN /* */ = "UNKNOWN" -export const SCRIPT /* */ = "SCRIPT" -export const TRANSACTION /* */ = "TRANSACTION" -export const GET_TRANSACTION_STATUS /* */ = "GET_TRANSACTION_STATUS" -export const GET_ACCOUNT /* */ = "GET_ACCOUNT" -export const GET_EVENTS /* */ = "GET_EVENTS" -export const PING /* */ = "PING" -export const GET_TRANSACTION /* */ = "GET_TRANSACTION" -export const GET_BLOCK /* */ = "GET_BLOCK" -export const GET_BLOCK_HEADER /* */ = "GET_BLOCK_HEADER" -export const GET_COLLECTION /* */ = "GET_COLLECTION" -export const GET_NETWORK_PARAMETERS /* */ = "GET_NETWORK_PARAMETERS" - -export const BAD /* */ = "BAD" -export const OK /* */ = "OK" +export enum InteractionStatus { + BAD = "BAD", + OK = "OK", +} -export const ACCOUNT /* */ = "ACCOUNT" -export const PARAM /* */ = "PARAM" -export const ARGUMENT /* */ = "ARGUMENT" +export enum TransactionRole { + AUTHORIZER = "authorizer", + PAYER = "payer", + PROPOSER = "proposer", +} -export const AUTHORIZER /* */ = "authorizer" -export const PAYER /* */ = "payer" -export const PROPOSER /* */ = "proposer" +export enum InteractionResolverKind { + ARGUMENT = "ARGUMENT", + ACCOUNT = "ACCOUNT", +} export interface InteractionAccount { - "kind": typeof ACCOUNT, - "tempId": string | null, - "addr": string | null, - "keyId": number | string | null, - "sequenceNum": number | null, - "signature": any | null, - "signingFunction": any | null, - "resolve": any | null, - "role": { - "proposer": boolean, - "authorizer": boolean, - "payer": boolean, - "param"?: boolean, - }, - authorization: any, + kind: InteractionResolverKind.ACCOUNT + tempId: string | null + addr: string | null + keyId: number | string | null + sequenceNum: number | null + signature: any | null + signingFunction: any | null + resolve: any | null + role: { + proposer: boolean + authorizer: boolean + payer: boolean + param?: boolean + } + authorization: any } export interface Interaction { - "tag": string, - "assigns": Record, - "status": string, - "reason": string | null, - "accounts": Record, - "params": Record, - "arguments": Record, - "message": { - "cadence": string | null, - "refBlock": string | null, - "computeLimit": string | null, - "proposer": string | null, - "payer": string | null, - "authorizations": string[], - "params": Record[], - "arguments": string[] - }, - "proposer": string | null, - "authorizations": string[], - "payer": string[], - "events": { - "eventType": string | null, - "start": string | null, - "end": string | null, - "blockIds": string[] - }, - "transaction": { - "id": string | null - }, - "block": { - "id": string | null, - "height": string | null, - "isSealed": boolean | null - }, - "account": { - "addr": string | null - }, - "collection": { - "id": string | null + tag: InteractionTag + assigns: Record + status: InteractionStatus + reason: string | null + accounts: Record + params: Record + arguments: Record + message: { + cadence: string | null + refBlock: string | null + computeLimit: string | null + proposer: string | null + payer: string | null + authorizations: string[] + params: Record[] + arguments: string[] } -} \ No newline at end of file + proposer: string | null + authorizations: string[] + payer: string[] + events: { + eventType: string | null + start: string | null + end: string | null + blockIds: string[] + } + transaction: { + id: string | null + } + block: { + id: string | null + height: string | null + isSealed: boolean | null + } + account: { + addr: string | null + } + collection: { + id: string | null + } +}