Skip to content

Commit

Permalink
Fix encoding/decoding of Address, change type of prefix in persistent…
Browse files Browse the repository at this point in the history
…Map.ts to uint8array
  • Loading branch information
sidenaio committed Feb 1, 2023
1 parent 5653e52 commit dd84aea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bindgen/assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ function write_region<T>(value: T) : usize {
function obj_to_bytes<T>(val: T) : Uint8Array {
var data : Uint8Array;
// @ts-ignore
if (isDefined(val.encode) || isArrayLike<T>() ) {
if (isDefined(val.encode) || (isArrayLike<T>() && !(val instanceof Uint8Array))) {
return encode<T>(val);
} else {
return encodeToBytes(val);
Expand All @@ -514,7 +514,7 @@ function obj_to_bytes<T>(val: T) : Uint8Array {
function bytes_to_obj<T>(data : Bytes) : T {
var value : T;
// @ts-ignore
if (isDefined(value.decode) || isArrayLike<T>()) {
if (isDefined(value.decode) || (isArrayLike<T>() && !(value instanceof Uint8Array))) {
return decode<T>(data);
}
return decodeBytes<T>(data);
Expand Down
8 changes: 6 additions & 2 deletions sdk-core/assembly/persistentMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ export class PersistentMap<K, V> {
private _elementPrefix: Bytes;

constructor(
prefix: string) {
this._elementPrefix = Bytes.fromBytes(util.stringToBytes(prefix));
prefix: Uint8Array) {
this._elementPrefix = Bytes.fromBytes(prefix);
}

static withStringPrefix<K, V>(prefix : string) : PersistentMap<K,V> {
return new PersistentMap<K,V>(Bytes.fromBytes(util.stringToBytes(prefix)));
}

private encodeKey(key: K): usize {
Expand Down

0 comments on commit dd84aea

Please sign in to comment.