mirror of
https://github.com/alexgo-io/clarity-codegen.git
synced 2026-01-12 22:22:01 +08:00
feat: allow to set deployerAddress when calling composeTxOptions, executeReadonlyCall
This commit is contained in:
@@ -14,13 +14,13 @@ import {
|
||||
} from "./contractBase";
|
||||
|
||||
export interface ContractCallOptions {
|
||||
contractAddress: string;
|
||||
contractName: string;
|
||||
functionName: string;
|
||||
functionArgs: ClarityValue[];
|
||||
anchorMode: AnchorMode;
|
||||
postConditionMode: PostConditionMode;
|
||||
postConditions?: PostCondition[];
|
||||
contractAddress: string;
|
||||
contractName: string;
|
||||
functionName: string;
|
||||
functionArgs: ClarityValue[];
|
||||
anchorMode: AnchorMode;
|
||||
postConditionMode: PostConditionMode;
|
||||
postConditions?: PostCondition[];
|
||||
}
|
||||
|
||||
export type ComposeTxOptionsFn<Contracts extends ContractBaseType> = <
|
||||
@@ -34,6 +34,7 @@ export type ComposeTxOptionsFn<Contracts extends ContractBaseType> = <
|
||||
? ParameterObjOfDescriptor<Descriptor>
|
||||
: never,
|
||||
options?: {
|
||||
deployerAddress?: string;
|
||||
postConditions?: (FungiblePostCondition | STXPostCondition)[];
|
||||
}
|
||||
) => ContractCallOptions;
|
||||
@@ -42,7 +43,7 @@ export const composeTxOptionsFactory =
|
||||
<T extends ContractBaseType>(
|
||||
contracts: T,
|
||||
factoryOptions: {
|
||||
deployerAddress: string;
|
||||
deployerAddress?: string;
|
||||
}
|
||||
): ComposeTxOptionsFn<T> =>
|
||||
(contractName, functionName, args, options = {}) => {
|
||||
@@ -50,7 +51,7 @@ export const composeTxOptionsFactory =
|
||||
|
||||
if (functionDescriptor.mode !== "public") {
|
||||
throw new Error(
|
||||
`[composeTx] function ${contractName}.${functionName} should be a public function`
|
||||
`[composeTxOptionsFactory] function ${contractName}.${functionName} should be a public function`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -64,11 +65,17 @@ export const composeTxOptionsFactory =
|
||||
: PostConditionMode.Deny;
|
||||
const postConditions = options.postConditions;
|
||||
|
||||
const deployerAddress =
|
||||
options.deployerAddress ?? factoryOptions.deployerAddress;
|
||||
if (deployerAddress == null) {
|
||||
throw new Error(`[composeTxOptionsFactory] deployer address required`);
|
||||
}
|
||||
|
||||
return {
|
||||
contractAddress: deployerAddress,
|
||||
contractName,
|
||||
functionName,
|
||||
functionArgs: clarityArgs,
|
||||
contractAddress: factoryOptions.deployerAddress,
|
||||
anchorMode: AnchorMode.Any,
|
||||
postConditionMode,
|
||||
postConditions,
|
||||
|
||||
@@ -20,6 +20,7 @@ export type ExecuteReadonlyCallFn<Contracts extends ContractBaseType> = <
|
||||
? ParameterObjOfDescriptor<Descriptor>
|
||||
: never,
|
||||
options?: {
|
||||
deployerAddress?: string;
|
||||
senderAddress?: string;
|
||||
callReadOnlyFunction?: CallReadOnlyFunctionFn;
|
||||
}
|
||||
@@ -33,7 +34,7 @@ export const executeReadonlyCallFactory =
|
||||
<T extends ContractBaseType>(
|
||||
contracts: T,
|
||||
factoryOptions: {
|
||||
deployerAddress: string;
|
||||
deployerAddress?: string;
|
||||
defaultSenderAddress?: string;
|
||||
callReadOnlyFunction?: CallReadOnlyFunctionFn;
|
||||
}
|
||||
@@ -51,10 +52,16 @@ export const executeReadonlyCallFactory =
|
||||
arg.type.encode(args[arg.name])
|
||||
);
|
||||
|
||||
const deployerAddress =
|
||||
options.deployerAddress ?? factoryOptions.defaultSenderAddress;
|
||||
if (deployerAddress == null) {
|
||||
throw new Error(`[composeTxOptionsFactory] deployer address required`);
|
||||
}
|
||||
|
||||
const senderAddress =
|
||||
options.senderAddress ??
|
||||
factoryOptions.defaultSenderAddress ??
|
||||
factoryOptions.deployerAddress;
|
||||
deployerAddress;
|
||||
|
||||
const _callReadOnlyFunction =
|
||||
options.callReadOnlyFunction ??
|
||||
@@ -65,7 +72,7 @@ export const executeReadonlyCallFactory =
|
||||
contractName,
|
||||
functionName,
|
||||
functionArgs: clarityArgs,
|
||||
contractAddress: factoryOptions.deployerAddress,
|
||||
contractAddress: deployerAddress,
|
||||
senderAddress,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user