@@ -5,63 +5,67 @@ import {prepTemplateOpts} from "./utils/prep-template-opts.js"
55import { preMutate } from "./utils/pre.js"
66import { isNumber } from "./utils/is"
77
8- /**
9- * @description
10- * Allows you to submit transactions to the blockchain to potentially mutate the state.
11- *
12- * @param { object } opts - Mutation Options and configuration
13- * @param {string } opts.platform - platform that runs the function
14- * @param {string } opts.cadence - Cadence Transaction used to mutate Flow
15- * @param {import("../fcl ").ArgsFn } [opts.args] - Arguments passed to cadence transaction
16- * @param {object } [opts.template] - Interaction Template for a transaction
17- * @param {number } [opts.limit] - Compute Limit for transaction
18- * @returns { Promise<string> } Transaction Id
19- *
20- * @example
21- * fcl.mutate({
22- * cadence: `
23- * transaction(a: Int, b: Int, c: Address) {
24- * prepare(acct: AuthAccount) {
25- * log(acct)
26- * log(a)
27- * log(b)
28- * log(c)
29- * }
30- * }
31- * `,
32- * args: (arg, t) => [
33- * arg(6, t.Int),
34- * arg(7, t.Int),
35- * arg("0xba1132bc08f82fe2", t.Address) ,
36- * ],
37- * })
38- *
39- *
40- * Options:
41- * type Options = {
42- * template: InteractionTemplate | String // InteractionTemplate or url to one
43- * cadence: String!,
44- * args: (arg, t) => Array<Arg>,
45- * limit: Number,
46- * authz: AuthzFn, // will overload the trinity of signatory roles
47- * proposer: AuthzFn, // will overload the proposer signatory role
48- * payer: AuthzFn, // will overload the payer signatory role
49- * authorizations: [AuthzFn], // an array of authorization functions used as authorizations signatory roles
50- * }
51- */
52- export const getMutate = ( { platform } ) => async ( opts = { } ) => {
53- var txid
54- try {
55- await preMutate ( opts )
56- opts = await prepTemplateOpts ( opts )
57- const currentUser = getCurrentUser ( { platform } )
58- // Allow for a config to overwrite the authorization function.
59- // prettier-ignore
60- const authz = await sdk . config ( ) . get ( "fcl.authz" , currentUser ( ) . authorization )
61-
62- txid = sdk . config ( ) . overload ( opts . dependencies || { } , async ( ) =>
8+ export const getMutate = ( { platform } ) => {
9+ /**
10+ * @description
11+ * Allows you to submit transactions to the blockchain to potentially mutate the state.
12+ *
13+ * @param {object } [ opts] - Mutation Options and configuration
14+ * @param {string } [ opts.cadence] - Cadence Transaction used to mutate Flow
15+ * @param {import("../shared-exports ").ArgsFn } [opts.args] - Arguments passed to cadence transaction
16+ * @param {object | string } [opts.template] - Interaction Template for a transaction
17+ * @param {number } [opts.limit] - Compute Limit for transaction
18+ * @param { Function } [opts.authz] - Authorization function for transaction
19+ * @param { Function } [opts.proposer] - Proposer Authorization function for transaction
20+ * @param { Function } [opts.payer] - Payer Authorization function for transaction
21+ * @param { Array<Function> } [opts.authorizations] - Authorizations function for transaction
22+ * @returns { Promise<string> } Transaction Id
23+ *
24+ * @example
25+ * fcl.mutate({
26+ * cadence: `
27+ * transaction(a: Int, b: Int, c: Address) {
28+ * prepare(acct: AuthAccount) {
29+ * log(acct)
30+ * log(a)
31+ * log(b)
32+ * log(c)
33+ * }
34+ * }
35+ * ` ,
36+ * args: (arg, t) => [
37+ * arg(6, t.Int),
38+ * arg(7, t.Int),
39+ * arg("0xba1132bc08f82fe2", t.Address),
40+ * ],
41+ * })
42+ *
43+ *
44+ * Options:
45+ * type Options = {
46+ * template: InteractionTemplate | String // InteractionTemplate or url to one
47+ * cadence: String!,
48+ * args: (arg, t) => Array<Arg>,
49+ * limit: Number,
50+ * authz: AuthzFn, // will overload the trinity of signatory roles
51+ * proposer: AuthzFn, // will overload the proposer signatory role
52+ * payer: AuthzFn, // will overload the payer signatory role
53+ * authorizations: [AuthzFn], // an array of authorization functions used as authorizations signatory roles
54+ * }
55+ */
56+ const mutate = async ( opts = { } ) => {
57+ var txid
58+ try {
59+ await preMutate ( opts )
60+ opts = await prepTemplateOpts ( opts )
61+ const currentUser = getCurrentUser ( { platform } )
62+ // Allow for a config to overwrite the authorization function.
6363 // prettier-ignore
64- sdk . send ( [
64+ const authz = await sdk . config ( ) . get ( "fcl.authz" , currentUser ( ) . authorization )
65+
66+ txid = sdk . config ( ) . overload ( opts . dependencies || { } , async ( ) =>
67+ // prettier-ignore
68+ sdk . send ( [
6569 sdk . transaction ( opts . cadence ) ,
6670
6771 sdk . args ( normalizeArgs ( opts . args || [ ] ) ) ,
@@ -77,10 +81,13 @@ export const getMutate = ({platform}) => async (opts = {}) => {
7781 // opts.authorizations > [opts.authz > authz]
7882 sdk . authorizations ( opts . authorizations || [ opts . authz || authz ] ) ,
7983 ] ) . then ( sdk . decode )
80- )
84+ )
8185
82- return txid
83- } catch ( error ) {
84- throw error
86+ return txid
87+ } catch ( error ) {
88+ throw error
89+ }
8590 }
91+
92+ return mutate
8693}
0 commit comments