diff --git a/soroban-spec/fixtures/ts/package.json b/soroban-spec/fixtures/ts/package.json index a5f6605ce..15f71b1dc 100644 --- a/soroban-spec/fixtures/ts/package.json +++ b/soroban-spec/fixtures/ts/package.json @@ -5,17 +5,18 @@ "@stellar/freighter-api": "1.4.0", "buffer": "6.0.3", "soroban-client": "0.8.0", - "bigint-conversion": "2.4.1" + "bigint-conversion": "2.4.1", + "stellar-base": "9.0.0-soroban.3" }, "scripts": { "build": "node ./scripts/build.mjs" }, "exports": { - "require": "./dist/cjs/index.js", - "import": "./dist/esm/index.js" + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js" }, "typings": "dist/types/index.d.ts", "devDependencies": { "typescript": "5.0.4" } -} +} \ No newline at end of file diff --git a/soroban-spec/fixtures/ts/src/convert.ts b/soroban-spec/fixtures/ts/src/convert.ts index 647fb5997..da2006fcf 100644 --- a/soroban-spec/fixtures/ts/src/convert.ts +++ b/soroban-spec/fixtures/ts/src/convert.ts @@ -130,3 +130,17 @@ export function addressToScVal(addr: string): xdr.ScVal { let addrObj = Address.fromString(addr); return addrObj.toScVal(); } + +export function i128ToScVal(i: bigint): xdr.ScVal { + return xdr.ScVal.scvI128(new xdr.Int128Parts({ + lo: xdr.Uint64.fromString((i & BigInt(0xFFFFFFFFFFFFFFFFn)).toString()), + hi: xdr.Int64.fromString(((i >> BigInt(64)) & BigInt(0xFFFFFFFFFFFFFFFFn)).toString()), + })) +} + +export function u128ToScVal(i: bigint): xdr.ScVal { + return xdr.ScVal.scvU128(new xdr.UInt128Parts({ + lo: xdr.Uint64.fromString((i & BigInt(0xFFFFFFFFFFFFFFFFn)).toString()), + hi: xdr.Int64.fromString(((i >> BigInt(64)) & BigInt(0xFFFFFFFFFFFFFFFFn)).toString()), + })) +} \ No newline at end of file diff --git a/soroban-spec/fixtures/ts/src/index.ts b/soroban-spec/fixtures/ts/src/index.ts index b7b74679a..fdd3c5765 100644 --- a/soroban-spec/fixtures/ts/src/index.ts +++ b/soroban-spec/fixtures/ts/src/index.ts @@ -1,7 +1,7 @@ import * as SorobanClient from 'soroban-client'; import { xdr } from 'soroban-client'; import { Buffer } from "buffer"; -import { scValStrToJs, scValToJs, addressToScVal } from './convert.js'; +import { scValStrToJs, scValToJs, addressToScVal, u128ToScVal, i128ToScVal } from './convert.js'; import { invoke, InvokeArgs } from './invoke.js'; declare const Errors: { message: string }[] diff --git a/soroban-spec/src/gen/typescript/project_template/package.json b/soroban-spec/src/gen/typescript/project_template/package.json index 4902e4f13..29ad833e9 100644 --- a/soroban-spec/src/gen/typescript/project_template/package.json +++ b/soroban-spec/src/gen/typescript/project_template/package.json @@ -5,17 +5,18 @@ "@stellar/freighter-api": "1.4.0", "buffer": "6.0.3", "soroban-client": "0.8.0", - "bigint-conversion": "2.4.1" + "bigint-conversion": "2.4.1", + "stellar-base": "9.0.0-soroban.3" }, "scripts": { "build": "node ./scripts/build.mjs" }, "exports": { - "require": "./dist/cjs/index.js", - "import": "./dist/esm/index.js" + "require": "./dist/cjs/index.js", + "import": "./dist/esm/index.js" }, "typings": "dist/types/index.d.ts", "devDependencies": { "typescript": "5.0.4" } -} +} \ No newline at end of file diff --git a/soroban-spec/src/gen/typescript/project_template/src/convert.ts b/soroban-spec/src/gen/typescript/project_template/src/convert.ts index 647fb5997..da2006fcf 100644 --- a/soroban-spec/src/gen/typescript/project_template/src/convert.ts +++ b/soroban-spec/src/gen/typescript/project_template/src/convert.ts @@ -130,3 +130,17 @@ export function addressToScVal(addr: string): xdr.ScVal { let addrObj = Address.fromString(addr); return addrObj.toScVal(); } + +export function i128ToScVal(i: bigint): xdr.ScVal { + return xdr.ScVal.scvI128(new xdr.Int128Parts({ + lo: xdr.Uint64.fromString((i & BigInt(0xFFFFFFFFFFFFFFFFn)).toString()), + hi: xdr.Int64.fromString(((i >> BigInt(64)) & BigInt(0xFFFFFFFFFFFFFFFFn)).toString()), + })) +} + +export function u128ToScVal(i: bigint): xdr.ScVal { + return xdr.ScVal.scvU128(new xdr.UInt128Parts({ + lo: xdr.Uint64.fromString((i & BigInt(0xFFFFFFFFFFFFFFFFn)).toString()), + hi: xdr.Int64.fromString(((i >> BigInt(64)) & BigInt(0xFFFFFFFFFFFFFFFFn)).toString()), + })) +} \ No newline at end of file diff --git a/soroban-spec/src/gen/typescript/project_template/src/index.ts b/soroban-spec/src/gen/typescript/project_template/src/index.ts index 0cd3a6f2a..6255cc544 100644 --- a/soroban-spec/src/gen/typescript/project_template/src/index.ts +++ b/soroban-spec/src/gen/typescript/project_template/src/index.ts @@ -1,7 +1,7 @@ import * as SorobanClient from 'soroban-client'; import { xdr } from 'soroban-client'; import { Buffer } from "buffer"; -import { scValStrToJs, scValToJs, addressToScVal } from './convert.js'; +import { scValStrToJs, scValToJs, addressToScVal, u128ToScVal, i128ToScVal } from './convert.js'; import { invoke, InvokeArgs } from './invoke.js'; declare const Errors: { message: string }[] diff --git a/soroban-spec/src/gen/typescript/wrapper.rs b/soroban-spec/src/gen/typescript/wrapper.rs index ecb6134e5..6b1425491 100644 --- a/soroban-spec/src/gen/typescript/wrapper.rs +++ b/soroban-spec/src/gen/typescript/wrapper.rs @@ -45,12 +45,8 @@ pub fn type_to_js_xdr(value: &types::Type) -> String { types::Type::Bytes => "xdr.ScVal.scvBytes(i)".to_owned(), types::Type::Address => "addressToScVal(i)".to_owned(), types::Type::Void => "xdr.ScVal.scvVoid()".to_owned(), - types::Type::U128 => { - "xdr.ScVal.scvU128(xdr.Int128Parts.fromXDR(i.toString(16), 'hex'))".to_owned() - } - types::Type::I128 => { - "xdr.ScVal.scvI128(xdr.Int128Parts.fromXDR(i.toString(16), 'hex'))".to_owned() - } + types::Type::U128 => "u128ToScVal(i)".to_owned(), + types::Type::I128 => "i128ToScVal(i)".to_owned(), types::Type::I256 => todo!(), types::Type::U256 => todo!(), types::Type::String => "xdr.ScVal.scvString(i)".to_owned(),