Skip to content

Commit

Permalink
feat(utils): comment utils
Browse files Browse the repository at this point in the history
  • Loading branch information
esteblock committed Aug 1, 2023
1 parent 7ee418d commit ecb9ee9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 50 deletions.
56 changes: 28 additions & 28 deletions packages/utils/src/convert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,39 +64,39 @@ function bigNumberFromBytes(
return BigNumber(b.toString()).multipliedBy(sign)
}

export function bigNumberToI128(value: BigNumber): SorobanClient.xdr.ScVal {
const b: bigint = BigInt(value.toFixed(0))
const buf = bigintToBuf(b)
if (buf.length > 16) {
throw new Error('BigNumber overflows i128')
}
// export function bigNumberToI128(value: BigNumber): SorobanClient.xdr.ScVal {
// const b: bigint = BigInt(value.toFixed(0))
// const buf = bigintToBuf(b)
// if (buf.length > 16) {
// throw new Error('BigNumber overflows i128')
// }

if (value.isNegative()) {
// Clear the top bit
buf[0] &= 0x7f
}
// if (value.isNegative()) {
// // Clear the top bit
// buf[0] &= 0x7f
// }

// left-pad with zeros up to 16 bytes
let padded = Buffer.alloc(16)
buf.copy(padded, padded.length - buf.length)
console.debug({ value: value.toString(), padded })
// // left-pad with zeros up to 16 bytes
// let padded = Buffer.alloc(16)
// buf.copy(padded, padded.length - buf.length)
// console.debug({ value: value.toString(), padded })

if (value.isNegative()) {
// Set the top bit
padded[0] |= 0x80
}
// if (value.isNegative()) {
// // Set the top bit
// padded[0] |= 0x80
// }

const hi = new xdr.Uint64(
bigNumberFromBytes(false, ...padded.slice(4, 8)).toNumber(),
bigNumberFromBytes(false, ...padded.slice(0, 4)).toNumber()
)
const lo = new xdr.Uint64(
bigNumberFromBytes(false, ...padded.slice(12, 16)).toNumber(),
bigNumberFromBytes(false, ...padded.slice(8, 12)).toNumber()
)
// const hi = new xdr.Uint64(
// bigNumberFromBytes(false, ...padded.slice(4, 8)).toNumber(),
// bigNumberFromBytes(false, ...padded.slice(0, 4)).toNumber()
// )
// const lo = new xdr.Uint64(
// bigNumberFromBytes(false, ...padded.slice(12, 16)).toNumber(),
// bigNumberFromBytes(false, ...padded.slice(8, 12)).toNumber()
// )

return xdr.ScVal.scvI128(new xdr.Int128Parts({ lo, hi }))
}
// return xdr.ScVal.scvI128(new xdr.Int128Parts({ lo, hi }))
// }

function bigintToBuf(bn: bigint): Buffer {
var hex = BigInt(bn).toString(16).replace(/^-/, '')
Expand Down
44 changes: 22 additions & 22 deletions packages/utils/src/identifiers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ import * as SorobanClient from 'soroban-client'
let xdr = SorobanClient.xdr


export function accountIdentifier(account: string): SorobanClient.xdr.ScVal {
return xdr.ScVal.scvObject(
xdr.ScObject.scoVec([
xdr.ScVal.scvSymbol('Account'),
xdr.ScVal.scvObject(
xdr.ScObject.scoAccountId(xdr.PublicKey.publicKeyTypeEd25519(
SorobanClient.StrKey.decodeEd25519PublicKey(account)
))
),
])
)
}
// export function accountIdentifier(account: string): SorobanClient.xdr.ScVal {
// return xdr.ScVal.scvObject(
// xdr.ScObject.scoVec([
// xdr.ScVal.scvSymbol('Account'),
// xdr.ScVal.scvObject(
// xdr.ScObject.scoAccountId(xdr.PublicKey.publicKeyTypeEd25519(
// SorobanClient.StrKey.decodeEd25519PublicKey(account)
// ))
// ),
// ])
// )
// }

export function contractIdentifier(contractId: string): SorobanClient.xdr.ScVal {
return xdr.ScVal.scvObject(
xdr.ScObject.scoVec([
xdr.ScVal.scvSymbol('Contract'),
xdr.ScVal.scvObject(xdr.ScObject.scoBytes(
Buffer.from(contractId, 'hex')
)),
])
)
// export function contractIdentifier(contractId: string): SorobanClient.xdr.ScVal {
// return xdr.ScVal.scvObject(
// xdr.ScObject.scoVec([
// xdr.ScVal.scvSymbol('Contract'),
// xdr.ScVal.scvObject(xdr.ScObject.scoBytes(
// Buffer.from(contractId, 'hex')
// )),
// ])
// )

}
// }

0 comments on commit ecb9ee9

Please sign in to comment.