Skip to content

Commit

Permalink
UntypedValue and better signed transaction support
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpaulos committed Apr 2, 2024
1 parent b6ce561 commit f1cc269
Showing 1 changed file with 26 additions and 17 deletions.
43 changes: 26 additions & 17 deletions typescript_templates/model.vm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ BlockHeader##
bigint##
#end
#elseif ( $param.type == "object" )
Map<string, MsgpackEncodingData>##
UntypedValue##
#elseif ( $type_override == "number" || ( ( $param.type == "integer" || $param.arrayType == "integer" ) && $type_override.length() == 0 ) )
#if ( $isArgType )
(number | bigint)##
Expand Down Expand Up @@ -145,7 +145,7 @@ $value##
#set( $value = "this.#paramName($prop)" )
#if ( $prop.algorandFormat == "BlockHeader" )
blockHeaderMsgpackPrepare($value)##
#elseif ( "#isClassType($prop)" == "false" && $prop.algorandFormat != "SignedTransaction" )
#elseif ( "#isClassType($prop)" == "false" && $prop.algorandFormat != "SignedTransaction" && $prop.type != "object" )
$value##
#elseif ( $prop.arrayType )
${value}.map(v => v.msgpackPrepare())##
Expand All @@ -158,8 +158,8 @@ ${value}.msgpackPrepare()##
#set( $value = "this.#paramName($prop)" )
#set( $sdkType = "#toSdkType($className, $prop, false)" )
#if ( $prop.algorandFormat == "BlockHeader" )
$value##
#elseif ( "#isClassType($prop)" == "false" && $prop.algorandFormat != "SignedTransaction" && $sdkType != "Uint8Array" && $sdkType != "Uint8Array[]")
blockHeaderJSONPrepare($value)##
#elseif ( "#isClassType($prop)" == "false" && $prop.algorandFormat != "SignedTransaction" && $sdkType != "Uint8Array" && $sdkType != "Uint8Array[]" && $sdkType != "UntypedValue" )
$value##
#elseif ( $prop.arrayType )
#if ( $sdkType == "Uint8Array[]" )
Expand All @@ -175,17 +175,21 @@ ${value}.jsonPrepare()##
#end
## Create an expression to assign a field in the fromDecodedMsgpack function
#macro ( fromDecodedMsgpackAssignType $value $prop $className )
#set( $sdkType = "#toSdkType($className, $prop, false)" )
#if ( $sdkType == "SignedTransaction[]" )
#set ( $sdkType = "SignedTransaction" )
#end
#if ( $prop.algorandFormat == "BlockHeader" )
blockHeaderFromDecodedMsgpack($value)##
#elseif ( "#isClassType($prop)" == "false" && $prop.algorandFormat != "SignedTransaction" )
#elseif ( "#isClassType($prop)" == "false" && $sdkType != "SignedTransaction" && $sdkType != "UntypedValue")
#if ($prop.required)
$value ?? #defaultValueForType($className, $prop)##
#else
$value##
#end
#elseif ( $prop.arrayType )
#if ( $prop.algorandFormat == "SignedTransaction" )
#set ( $mapping = ".map(SignedTransaction.fromDecodedMsgpack)" )
#if ( $sdkType == "SignedTransaction" || $sdkType == "UntypedValue")
#set ( $mapping = ".map(${sdkType}.fromDecodedMsgpack)" )
#else
#set ( $mapping = ".map(${prop.arrayType}.fromDecodedMsgpack)" )
#end
Expand All @@ -195,8 +199,8 @@ $value##
typeof $value !== 'undefined' ? $value$mapping : undefined##
#end
#else
#if ( $prop.algorandFormat == "SignedTransaction" )
#set ( $assignment = "SignedTransaction.fromDecodedMsgpack" )
#if ( $sdkType == "SignedTransaction" || $sdkType == "UntypedValue")
#set ( $assignment = "${sdkType}.fromDecodedMsgpack" )
#else
#set ( $assignment = "${prop.refType}.fromDecodedMsgpack" )
#end
Expand All @@ -209,17 +213,21 @@ typeof $value !== 'undefined' ? $assignment($value) : undefined##
#end
## Create an expression to assign a field in the fromDecodedJSON function
#macro ( fromDecodedJSONAssignType $value $prop $className )
#set( $sdkType = "#toSdkType($className, $prop, false)" )
#if ( $sdkType == "SignedTransaction[]" )
#set ( $sdkType = "SignedTransaction" )
#end
#if ( $prop.algorandFormat == "BlockHeader" )
$value as BlockHeader##
#elseif ( "#isClassType($prop)" == "false" && $prop.algorandFormat != "SignedTransaction" )
blockHeaderFromDecodedJSON($value)##
#elseif ( "#isClassType($prop)" == "false" && $sdkType != "SignedTransaction" && $sdkType != "UntypedValue" )
#if ($prop.required)
$value ?? #defaultValueForType($className, $prop)##
#else
$value##
#end
#elseif ( $prop.arrayType )
#if ( $prop.algorandFormat == "SignedTransaction" )
#set ( $mapping = ".map(SignedTransaction.fromDecodedJSON)" )
#if ( $sdkType == "SignedTransaction" || $sdkType == "UntypedValue" )
#set ( $mapping = ".map(${sdkType}.fromDecodedJSON)" )
#else
#set ( $mapping = ".map(${prop.arrayType}.fromDecodedJSON)" )
#end
Expand All @@ -229,8 +237,8 @@ $value##
typeof $value !== 'undefined' ? $value$mapping : undefined##
#end
#else
#if ( $prop.algorandFormat == "SignedTransaction" )
#set ( $assignment = "SignedTransaction.fromDecodedJSON" )
#if ( $sdkType == "SignedTransaction" || $sdkType == "UntypedValue" )
#set ( $assignment = "${sdkType}.fromDecodedJSON" )
#else
#set ( $assignment = "${prop.refType}.fromDecodedJSON" )
#end
Expand All @@ -253,7 +261,7 @@ typeof $value !== 'undefined' ? $assignment($value) : undefined##
false##
#elseif ( $sdkType == "Uint8Array" )
new Uint8Array()##
#elseif ( $sdkType == "BlockHeader" || $sdkType == "Map<string, MsgpackEncodingData>" || $sdkType == "SignedTransaction" )
#elseif ( $sdkType == "BlockHeader" || $sdkType == "UntypedValue" || $sdkType == "SignedTransaction" )
{}##
#else
UNHANDLED DEFAULT TYPE
Expand Down Expand Up @@ -281,9 +289,10 @@ import { ensureBigInt, ensureSafeInteger } from '../../../../utils/utils.js';
import { MsgpackEncodable, MsgpackEncodingData, JSONEncodable, JSONEncodingData } from '../../../../encoding/encoding.js';
import { base64ToBytes, bytesToBase64 } from '../../../../encoding/binarydata.js';
#if ( $propFile.indexer == "false" )
import BlockHeader, { blockHeaderMsgpackPrepare, blockHeaderFromDecodedMsgpack } from '../../../../types/blockHeader.js';
import BlockHeader, { blockHeaderMsgpackPrepare, blockHeaderFromDecodedMsgpack, blockHeaderJSONPrepare, blockHeaderFromDecodedJSON } from '../../../../types/blockHeader.js';
import { SignedTransaction } from '../../../../signedTransaction.js';
#end
import { UntypedValue } from '../../untypedmodel.js';
// import BaseModel from '../../basemodel.js';

#foreach( $modelEntry in $models.entrySet() )
Expand Down

0 comments on commit f1cc269

Please sign in to comment.