Skip to content

Commit

Permalink
Merge branch 'attach-bundle' into condor
Browse files Browse the repository at this point in the history
  • Loading branch information
hoffmannjan committed Jul 5, 2024
2 parents 32d922d + e7075a7 commit e460d70
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/publish-casper-client-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ jobs:
token: ${{ secrets.NPM_TOKEN }}
tag: ${{ env.release_tag }}
access: "public"
- name: Get latest release version number
id: get_version
uses: battila7/get-version-action@v2
- run: cp dist/lib.js casper-js-sdk.v${{ steps.get_version.outputs.version }}.js
- uses: meeDamian/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
files: casper-js-sdk.v${{ steps.get_version.outputs.version }}.js
allow_override: true
64 changes: 55 additions & 9 deletions src/lib/CLValue/Key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ import {
CHAINSPEC_REGISTRY_PREFIX,
CHECKSUM_REGISTRY_PREFIX,
KeyBidAddr,
BidAddrParser
BidAddrParser,
KeyEntityAddrParser,
KeyEntityAddr,
ENTITY_PREFIX
} from './index';
import { toBytesNumber } from '../ByteConverters';
import { KEY_TYPE, CLTypeTag, KEY_DEFAULT_BYTE_LENGTH } from './constants';
Expand Down Expand Up @@ -90,7 +93,7 @@ export class CLKeyBytesParser extends CLValueBytesParsers {
case KeyTag.EraInfo:
return Ok(
concat([
Uint8Array.from([KeyTag.DeployInfo]),
Uint8Array.from([KeyTag.EraInfo]),
toBytesNumber(64, false)(value.data.data)
])
);
Expand Down Expand Up @@ -135,6 +138,20 @@ export class CLKeyBytesParser extends CLValueBytesParsers {
concat([Uint8Array.from([KeyTag.ChecksumRegistry]), padding])
);
}
case KeyTag.Unbond: {
return Ok(
concat([
Uint8Array.from([KeyTag.Unbond]),
new CLAccountHashBytesParser()
.toBytes(value.data as CLAccountHash)
.unwrap()
])
);
}
case KeyTag.AddressableEntity: {
const bytes = KeyEntityAddrParser.toBytes(value.data as KeyEntityAddr);
return Ok(concat([Uint8Array.from([KeyTag.AddressableEntity]), bytes]));
}
default:
throw new Error(
`Problem serializing keyVariant: ${value.data.keyVariant}`
Expand Down Expand Up @@ -211,10 +228,7 @@ export class CLKeyBytesParser extends CLValueBytesParsers {
return resultHelper(Ok(new CLKey(deploy)), remainder);
}
case KeyTag.EraInfo: {
const [eraBytes, remainder] = splitAt(
64,
contentBytes
);
const [eraBytes, remainder] = splitAt(64, contentBytes);
const era = new KeyEraInfo(eraBytes);
return resultHelper(Ok(new CLKey(era)), remainder);
}
Expand All @@ -223,19 +237,21 @@ export class CLKeyBytesParser extends CLValueBytesParsers {
KEY_DEFAULT_BYTE_LENGTH,
contentBytes
);
const balance= new KeyBalance(balanceBytes);
const balance = new KeyBalance(balanceBytes);
return resultHelper(Ok(new CLKey(balance)), remainder);
}
case KeyTag.BidAddr: {
const { result, remainder } = BidAddrParser.fromBytesWithRemainder(contentBytes);
const { result, remainder } = BidAddrParser.fromBytesWithRemainder(
contentBytes
);
if (result.ok) {
const key = new CLKey(result.val);
return resultHelper(Ok(key), remainder);
} else {
return resultHelper<CLKey, CLErrorCodes>(Err(result.val));
}
}
case KeyTag.Bid : {
case KeyTag.Bid: {
const [bidBytes, remainder] = splitAt(
KEY_DEFAULT_BYTE_LENGTH,
contentBytes
Expand Down Expand Up @@ -299,6 +315,34 @@ export class CLKeyBytesParser extends CLValueBytesParsers {
const keyPackage = new KeyPackage(packageBytes);
return resultHelper(Ok(new CLKey(keyPackage)), remainder);
}
case KeyTag.Unbond: {
const {
result: accountHashResult,
remainder: accountHashRemainder
} = new CLAccountHashBytesParser().fromBytesWithRemainder(
bytes.subarray(1)
);
if (accountHashResult.ok) {
const key = new CLKey(new KeyUnbond(accountHashResult.val));
return resultHelper(Ok(key), accountHashRemainder);
} else {
return resultHelper<CLKey, CLErrorCodes>(Err(accountHashResult.val));
}
}
case KeyTag.AddressableEntity: {
const {
result: addressableEntityResult,
remainder: addressableEntityRemainder
} = KeyEntityAddrParser.fromBytesWithRemainder(bytes.subarray(1));
if (addressableEntityResult.ok) {
const key = new CLKey(addressableEntityResult.val);
return resultHelper(Ok(key), addressableEntityRemainder);
} else {
return resultHelper<CLKey, CLErrorCodes>(
Err(addressableEntityResult.val)
);
}
}
default: {
return resultHelper<CLKey, CLErrorCodes>(Err(CLErrorCodes.Formatting));
}
Expand Down Expand Up @@ -375,6 +419,8 @@ export class CLKey extends CLValue {
return new CLKey(KeyChainspecRegistry.fromFormattedString(input));
case CHECKSUM_REGISTRY_PREFIX:
return new CLKey(KeyChecksumRegistry.fromFormattedString(input));
case ENTITY_PREFIX:
return new CLKey(KeyEntityAddr.fromFormattedString(input));
default:
throw new Error('Unsupported prefix');
}
Expand Down
6 changes: 3 additions & 3 deletions src/lib/CLValue/KeyVariants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,14 @@ export class KeyUnbond implements CLKeyVariant {
keyVariant = KeyTag.Unbond;
prefix = UNBOND_PREFIX;

constructor(public data: Uint8Array) {}
constructor(public data: CLAccountHash) {}

value(): any {
return this.data;
}

toString() {
return encodeBase16(this.data);
return this.data.toString();
}

toFormattedString() {
Expand All @@ -399,7 +399,7 @@ export class KeyUnbond implements CLKeyVariant {
const hashStr = input.substring(`${UNBOND_PREFIX}-`.length + 1);
const hashBytes = decodeBase16(hashStr);

return new KeyUnbond(hashBytes);
return new KeyUnbond(new CLAccountHash(hashBytes));
}
}

Expand Down

0 comments on commit e460d70

Please sign in to comment.