Skip to content

Commit

Permalink
fix(sui): better input handles on different types (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 authored Nov 9, 2024
1 parent 87f1a49 commit 4e1b342
Show file tree
Hide file tree
Showing 5 changed files with 1,528 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/move/src/codegen/abstract-codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export abstract class AbstractCodegen<ModuleTypes, StructType> {
return 'string'
case 'bool':
case 'Bool':
return 'Boolean'
return 'boolean'
case 'u8':
case 'U8':
case 'u16':
Expand Down
59 changes: 56 additions & 3 deletions packages/sui/src/codegen/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,55 @@ export class SuiCodegen extends AbstractCodegen<
callValue: `_args.push(transactionArgumentOrObject(args[${idx}], tx))`
})
} else if (arg.isVector()) {
// TODO fix pure vector
args.push({
paramType: `(${this.ADDRESS_TYPE} | TransactionObjectArgument)[] | TransactionArgument`,
callValue: `_args.push(transactionArgumentOrVec(args[${idx}], tx))`
})
} else {
// Handle pure type
let pureFunction = ''
const paramType = `${this.generateTypeForDescriptor(arg, module.address)} | TransactionArgument`

switch (arg.qname.toLowerCase()) {
case 'u8':
pureFunction = `transactionArgumentOrPureU8`
break
case 'u16':
pureFunction = `transactionArgumentOrPureU16`
break
case 'u32':
pureFunction = `transactionArgumentOrPureU32`
break
case 'u64':
pureFunction = `transactionArgumentOrPureU64`
break
case 'u128':
pureFunction = `transactionArgumentOrPureU128`
break
case 'u256':
pureFunction = `transactionArgumentOrPureU256`
break
case 'bool':
pureFunction = `transactionArgumentOrPureBool`
break
case 'string':
pureFunction = `transactionArgumentOrPureString`
break
case 'address':
pureFunction = `transactionArgumentOrPureAddress`
break
// case 'vector':
// case 'option':
default:
pureFunction = `transactionArgumentOrPure`
// paramType = 'TransactionArgument'
}
const callValue = pureFunction ? `_args.push(${pureFunction}(args[${idx}], tx))` : `_args.push(args[${idx}])`

args.push({
paramType: `${this.generateTypeForDescriptor(arg, module.address)} | TransactionArgument`,
callValue: `_args.push(transactionArgumentOrPure(args[${idx}], tx))`
paramType,
callValue
})
}
}
Expand Down Expand Up @@ -225,7 +266,19 @@ export class SuiCodegen extends AbstractCodegen<
import { ZERO_ADDRESS, TypedDevInspectResults, getMoveCoder } from '@typemove/sui'
import { Transaction, TransactionArgument, TransactionObjectArgument } from '@mysten/sui/transactions'
import { SuiClient } from '@mysten/sui/client'
import { transactionArgumentOrObject, transactionArgumentOrPure, transactionArgumentOrVec } from '@typemove/sui'
import { transactionArgumentOrObject,
transactionArgumentOrVec,
transactionArgumentOrPure,
transactionArgumentOrPureU8,
transactionArgumentOrPureU16,
transactionArgumentOrPureU32,
transactionArgumentOrPureU64,
transactionArgumentOrPureU128,
transactionArgumentOrPureU256,
transactionArgumentOrPureBool,
transactionArgumentOrPureString,
transactionArgumentOrPureAddress,
} from '@typemove/sui'
`
}
}
Loading

0 comments on commit 4e1b342

Please sign in to comment.