-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
interface Requests { | ||
stx_contractCall: { | ||
args: { | ||
/** | ||
* The stacks address of sender. | ||
*/ | ||
pubkey: string; | ||
|
||
/** | ||
* The address of the contract. | ||
*/ | ||
contractAddress: string; | ||
|
||
/** | ||
* The name of the contract. | ||
*/ | ||
contractName: string; | ||
|
||
/** | ||
* The name of the function to call. | ||
*/ | ||
functionName: string; | ||
|
||
/** | ||
* An array of hex-encoded strings representing the function arguments. | ||
* | ||
* To convert Clarity values to their hex representation, the `cvToString` | ||
* helper from the `@stacks/transactions` package may be helpful. | ||
* | ||
* ```js | ||
* import { cvToString } from '@stacks/transactions'; | ||
* | ||
* const functionArgs = [someClarityValue1, someClarityValue2]; | ||
* const hexArgs = functionArgs.map(cvToString); | ||
* ``` | ||
*/ | ||
functionArgs: Array<string>; | ||
|
||
/** | ||
* A hex-encoded string representing the post conditions. | ||
* | ||
* A post condition may be converted to it's hex representation using the `serializePostCondition` helper from the `@stacks/transactions` package, | ||
* | ||
* ```js | ||
* import { serializePostCondition } from '@stacks/transactions'; | ||
* | ||
* const postCondition = somePostCondition; | ||
* const hexPostCondition = serializePostCondition(postCondition).toString('hex'); | ||
*/ | ||
postConditions: Array<string>; // Array<PostCondition> | ||
|
||
/** | ||
* The mode of the post conditions. | ||
*/ | ||
postConditionMode?: number; // PostConditionMode | ||
|
||
/** | ||
* The anchor mode. | ||
*/ | ||
anchorMode?: 'TODO'; // AnchorMode | ||
/** A stringified BigInt */ | ||
nonce?: string; // BigInt | ||
version?: string; | ||
sponsored?: boolean; | ||
}; | ||
return: {}; | ||
}; | ||
stx_transfer: { | ||
args: { | ||
pubkey: string; | ||
recipient: string; | ||
amount: string; // BigInt | ||
memo?: string; | ||
postConditions?: Array<string>; // Array<PostCond> | ||
postConditionMode?: string; // PostConditionMode | ||
version?: string; | ||
}; | ||
return: {}; | ||
}; | ||
stx_signMessage: { | ||
args: { | ||
pubkey: string; | ||
message: string; | ||
version?: string; | ||
}; | ||
return: {}; | ||
}; | ||
stx_contractDeploy: { | ||
args: { | ||
pubkey: string; | ||
contractName: string; | ||
codeBody: string; | ||
postConditions?: Array<string>; // Array<PostCond> | ||
postConditionMode?: string; // PostConditionMode | ||
version?: string; | ||
}; | ||
return: {}; | ||
}; | ||
} | ||
|
||
type Return<Method> = Method extends keyof Requests ? Requests[Method]['return'] : unknown; | ||
type Args<Method> = Method extends keyof Requests ? Requests[Method]['args'] : unknown; | ||
|
||
function request<Method extends keyof Requests>( | ||
requestMethod: Method, | ||
args: Args<Method>, | ||
): Return<Method> { | ||
switch (requestMethod) { | ||
// case 'stx_foo1': { | ||
// return { resultA: 'value' } as Return<Method>; | ||
// } | ||
default: | ||
return {} as Return<Method>; | ||
} | ||
} |