Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
"tslib": "^2.6.2"
},
"dependencies": {
"@algorandfoundation/algorand-typescript": "^1.0.0-beta.6",
"@algorandfoundation/puya-ts": "^1.0.0-beta.10",
"@algorandfoundation/algorand-typescript": "^1.0.0-beta.7",
"@algorandfoundation/puya-ts": "^1.0.0-beta.11",
"elliptic": "^6.5.7",
"js-sha256": "^0.11.0",
"js-sha3": "^0.9.3",
Expand Down
17 changes: 8 additions & 9 deletions src/impl/pure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,30 +103,29 @@ export const expw = (a: internal.primitives.StubUint64Compat, b: internal.primit
return toUint128(base ** exponent)
}

export const extract = (
type ExtractType = ((a: internal.primitives.StubBytesCompat, b: internal.primitives.StubUint64Compat) => bytes) &
((a: internal.primitives.StubBytesCompat, b: internal.primitives.StubUint64Compat, c: internal.primitives.StubUint64Compat) => bytes)
export const extract = ((
a: internal.primitives.StubBytesCompat,
b: internal.primitives.StubUint64Compat,
c: internal.primitives.StubUint64Compat,
c?: internal.primitives.StubUint64Compat,
): bytes => {
const bytesValue = internal.primitives.BytesCls.fromCompat(a)
const bytesLength = bytesValue.length.asBigInt()

const start = internal.primitives.Uint64Cls.fromCompat(b).asBigInt()
const length = internal.primitives.Uint64Cls.fromCompat(c).asBigInt()
let end = start + length
if ((typeof b === 'number' || typeof b === 'bigint') && (typeof c === 'number' || typeof c === 'bigint') && length === 0n) {
end = bytesLength
}
const length = c !== undefined ? internal.primitives.Uint64Cls.fromCompat(c).asBigInt() : undefined
const end = length !== undefined ? start + length : undefined

if (start > bytesLength) {
internal.errors.codeError(`extraction start ${start} is beyond length`)
}
if (end > bytesLength) {
if (end !== undefined && end > bytesLength) {
internal.errors.codeError(`extraction end ${end} is beyond length`)
}

return bytesValue.slice(start, end).asAlgoTs()
}
}) as ExtractType

export const extractUint16 = (a: internal.primitives.StubBytesCompat, b: internal.primitives.StubUint64Compat): uint64 => {
const result = extract(a, b, 2)
Expand Down
3 changes: 1 addition & 2 deletions tests/artifacts/miscellaneous-ops/contract.algo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@ export class MiscellaneousOpsContract extends arc4.Contract {
return result
}

// TODO: recompile to check if this results in correct TEAL code
@arc4.abimethod()
public verify_extract_from_2(a: bytes): bytes {
const result = op.extract(a, 2, 0)
const result = op.extract(a, 2)
return result
}

Expand Down
Loading
Loading