Skip to content

Commit

Permalink
Merge pull request #151 from casper-ecosystem/hotfix/fixed-stored-value
Browse files Browse the repository at this point in the history
Casper-js-sdk 2.9.1
  • Loading branch information
hoffmannjan authored Mar 22, 2022
2 parents b54eb9e + 02361fc commit 7da7c50
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ All notable changes to casper-js-sdk.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.9.1

### Fixed

- Got rid of unnecessary instanceof.
- Reverted StoredValue and added `{ rawData: boolean }` to `getDictionaryItemByName` and `getDictionaryItemByURef`.

## 2.9.0

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "casper-js-sdk",
"version": "2.9.0",
"version": "2.9.1",
"license": "Apache 2.0",
"description": "SDK to interact with the Casper blockchain",
"homepage": "https://github.com/casper-ecosystem/casper-js-sdk#README.md",
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class Contract {
path
);

if (contractData && contractData.CLValue instanceof CLValue) {
if (contractData && contractData.CLValue?.isCLValue) {
return contractData.CLValue.value();
} else {
throw Error('Invalid stored value');
Expand Down Expand Up @@ -145,7 +145,7 @@ export class Contract {
dictionaryItemKey
);

if (storedValue && storedValue.CLValue instanceof CLValue) {
if (storedValue && storedValue.CLValue?.isCLValue) {
return storedValue.CLValue;
} else {
throw Error('Invalid stored value');
Expand Down
3 changes: 1 addition & 2 deletions src/lib/StoredValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,9 @@ export class ContractPackageJson {
@jsonObject
export class StoredValue {
@jsonMember({
name: 'CLValue',
deserializer: json => {
if (!json) return;
return { ...CLValueParsers.fromJSON(json).unwrap(), raw: json };
return CLValueParsers.fromJSON(json).unwrap();
}
})
public CLValue?: CLValue;
Expand Down
22 changes: 14 additions & 8 deletions src/services/CasperServiceByJsonRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ export class CasperServiceByJsonRPC {
public async getDictionaryItemByURef(
stateRootHash: string,
dictionaryItemKey: string,
seedUref: string
seedUref: string,
{ rawData } = { rawData: false }
): Promise<StoredValue> {
const res = await this.client.request({
method: 'state_get_dictionary_item',
Expand All @@ -504,9 +505,11 @@ export class CasperServiceByJsonRPC {
return res;
} else {
const storedValueJson = res.stored_value;
const serializer = new TypedJSON(StoredValue);
const storedValue = serializer.parse(storedValueJson)!;
return storedValue;
if (!rawData) {
const serializer = new TypedJSON(StoredValue);
return serializer.parse(storedValueJson)!;
}
return storedValueJson;
}
}

Expand All @@ -519,7 +522,8 @@ export class CasperServiceByJsonRPC {
stateRootHash: string,
contractHash: string,
dictionaryName: string,
dictionaryItemKey: string
dictionaryItemKey: string,
{ rawData } = { rawData: false }
): Promise<StoredValue> {
const res = await this.client.request({
method: 'state_get_dictionary_item',
Expand All @@ -538,9 +542,11 @@ export class CasperServiceByJsonRPC {
return res;
} else {
const storedValueJson = res.stored_value;
const serializer = new TypedJSON(StoredValue);
const storedValue = serializer.parse(storedValueJson)!;
return storedValue;
if (!rawData) {
const serializer = new TypedJSON(StoredValue);
return serializer.parse(storedValueJson)!;
}
return storedValueJson;
}
}
}

0 comments on commit 7da7c50

Please sign in to comment.