@@ -10,9 +10,8 @@ import {
1010 Script ,
1111 scriptToBytecode ,
1212} from '@cashscript/utils' ;
13- import { Transaction } from './Transaction.js' ;
1413import {
15- ConstructorArgument , encodeFunctionArgument , encodeConstructorArguments , encodeFunctionArguments , FunctionArgument ,
14+ ConstructorArgument , encodeFunctionArgument , encodeConstructorArguments , FunctionArgument ,
1615} from './Argument.js' ;
1716import {
1817 Unlocker , ContractOptions , GenerateUnlockingBytecodeOptions , Utxo , AddressType , ContractUnlocker ,
@@ -29,12 +28,10 @@ export class Contract<
2928 TArtifact extends Artifact = Artifact ,
3029 TResolved extends {
3130 constructorInputs : ConstructorArgument [ ] ;
32- functions : Record < string , any > ;
3331 unlock : Record < string , any > ;
3432 }
3533 = {
3634 constructorInputs : ParamsToTuple < TArtifact [ 'constructorInputs' ] > ;
37- functions : AbiToFunctionMap < TArtifact [ 'abi' ] , Transaction > ;
3835 unlock : AbiToFunctionMap < TArtifact [ 'abi' ] , Unlocker > ;
3936 } ,
4037> {
@@ -44,10 +41,7 @@ export class Contract<
4441 bytecode : string ;
4542 bytesize : number ;
4643 opcount : number ;
47-
48- functions : TResolved [ 'functions' ] ;
4944 unlock : TResolved [ 'unlock' ] ;
50-
5145 redeemScript : Script ;
5246 public provider : NetworkProvider ;
5347 public addressType : AddressType ;
@@ -79,21 +73,7 @@ export class Contract<
7973
8074 this . redeemScript = generateRedeemScript ( asmToScript ( this . artifact . bytecode ) , this . encodedConstructorArgs ) ;
8175
82- // Populate the functions object with the contract's functions
83- // (with a special case for single function, which has no "function selector")
84- this . functions = { } ;
85- if ( artifact . abi . length === 1 ) {
86- const f = artifact . abi [ 0 ] ;
87- // @ts -ignore TODO: see if we can use generics to make TypeScript happy
88- this . functions [ f . name ] = this . createFunction ( f ) ;
89- } else {
90- artifact . abi . forEach ( ( f , i ) => {
91- // @ts -ignore TODO: see if we can use generics to make TypeScript happy
92- this . functions [ f . name ] = this . createFunction ( f , i ) ;
93- } ) ;
94- }
95-
96- // Populate the functions object with the contract's functions
76+ // Populate the 'unlock' object with the contract's functions
9777 // (with a special case for single function, which has no "function selector")
9878 this . unlock = { } ;
9979 if ( artifact . abi . length === 1 ) {
@@ -124,27 +104,6 @@ export class Contract<
124104 return this . provider . getUtxos ( this . address ) ;
125105 }
126106
127- private createFunction ( abiFunction : AbiFunction , selector ?: number ) : ContractFunction {
128- return ( ...args : FunctionArgument [ ] ) => {
129- if ( abiFunction . inputs . length !== args . length ) {
130- throw new Error ( `Incorrect number of arguments passed to function ${ abiFunction . name } . Expected ${ abiFunction . inputs . length } arguments (${ abiFunction . inputs . map ( ( input ) => input . type ) } ) but got ${ args . length } ` ) ;
131- }
132-
133- // Encode passed args (this also performs type checking)
134- const encodedArgs = encodeFunctionArguments ( abiFunction , args ) ;
135-
136- const unlocker = this . createUnlocker ( abiFunction , selector ) ( ...args ) ;
137-
138- return new Transaction (
139- this ,
140- unlocker ,
141- abiFunction ,
142- encodedArgs ,
143- selector ,
144- ) ;
145- } ;
146- }
147-
148107 private createUnlocker ( abiFunction : AbiFunction , selector ?: number ) : ContractFunctionUnlocker {
149108 return ( ...args : FunctionArgument [ ] ) => {
150109 if ( abiFunction . inputs . length !== args . length ) {
@@ -179,5 +138,4 @@ export class Contract<
179138 }
180139}
181140
182- export type ContractFunction = ( ...args : FunctionArgument [ ] ) => Transaction ;
183141type ContractFunctionUnlocker = ( ...args : FunctionArgument [ ] ) => ContractUnlocker ;
0 commit comments