Skip to content

Commit

Permalink
Update albatross client, add support for reactivation in update-staker
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Nov 21, 2023
1 parent ca6e3cd commit f5f3b1d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
11 changes: 10 additions & 1 deletion client/src/PublicRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,18 @@ export type SignTransactionRequest

export type SignStakingRequest = SignTransactionRequestCommon & {
type: number, // See SignStakingApi for types
recipientLabel?: string,

// For createStaker and updateStaker transactions
delegation?: string,

// For updateStaker transactions
reactivateAllStake?: boolean,

// For inactivateStake transactions
newInactiveBalance?: number,

// For unstake transactions
recipientLabel?: string,
};

export type SignBtcTransactionRequestStandard = SimpleRequest & BitcoinTransactionInfo & {
Expand Down
6 changes: 5 additions & 1 deletion src/request/sign-staking/SignStaking.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ class SignStaking {
tx = Albatross.TransactionBuilder.newUpdateStaker(
keyPair.toAddress(),
Albatross.Address.fromString(/** @type {Nimiq.Address} */ (request.delegation).toHex()),
Boolean(request.reactivateAllStake),
BigInt(request.transaction.fee),
request.transaction.validityStartHeight,
request.transaction.networkId,
Expand Down Expand Up @@ -210,7 +211,7 @@ class SignStaking {
throw new Errors.KeyguardError('Unreachable');
}

tx = tx.sign(keyPair);
tx.sign(keyPair);

/** @type {KeyguardRequest.SignStakingResult} */
const result = {
Expand Down Expand Up @@ -255,6 +256,9 @@ class SignStaking {
} else {
text += ' to no validator';
}
if (buf.readUint8() === 1) {
text += ' and reactivate all stake';
}
return text;
}
case SignStakingApi.IncomingStakingType.ADD_STAKE: {
Expand Down
5 changes: 5 additions & 0 deletions src/request/sign-staking/SignStakingApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@ class SignStakingApi extends TopLevelApi {
case SignStakingApi.IncomingStakingType.CREATE_STAKER:
case SignStakingApi.IncomingStakingType.UPDATE_STAKER: {
parsedRequest.delegation = this.parseAddress(request.delegation, 'delegation');
parsedRequest.reactivateAllStake = this.parseBoolean(request.reactivateAllStake);
const data = new Nimiq.SerialBuffer(
1 // Data type
+ 1 // Option<> indicator
+ Nimiq.Address.SERIALIZED_SIZE // Validator address (delegation)
+ (type === SignStakingApi.IncomingStakingType.UPDATE_STAKER ? 1 : 0) // Stake reactivation boolean
+ Nimiq.SignatureProof.SINGLE_SIG_SIZE, // Staker signature
);
data.writeUint8(type);
data.writeUint8(1); // Delegation is optional, this signals that we are including it.
data.write(parsedRequest.delegation.serialize());
if (type === SignStakingApi.IncomingStakingType.UPDATE_STAKER) {
data.writeUint8(parsedRequest.reactivateAllStake ? 1 : 0);
}
request.data = data;
isSignalling = type === SignStakingApi.IncomingStakingType.UPDATE_STAKER;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/request/sign-transaction/SignTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class SignTransaction {
);
}

tx = tx.sign(keyPair);
tx.sign(keyPair);

/** @type {KeyguardRequest.SignTransactionResult} */
const result = {
Expand Down
3 changes: 1 addition & 2 deletions tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,7 @@ cp -v node_modules/@nimiq/core-web/web.js \

# copy Albatross files
output "‼️ Copying Albatross files"
cp -vr node_modules/@nimiq/albatross-wasm/client-proxy.js \
node_modules/@nimiq/albatross-wasm/transfer-handlers.js \
cp -vr node_modules/@nimiq/albatross-wasm/lib \
node_modules/@nimiq/albatross-wasm/web \
dist/assets/albatross

Expand Down
9 changes: 5 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,12 @@
"@ethersproject/strings" "^5.7.0"

"@nimiq/albatross-wasm@npm:@nimiq/core-web@next":
version "2.0.0-alpha.13"
resolved "https://registry.yarnpkg.com/@nimiq/core-web/-/core-web-2.0.0-alpha.13.tgz#6fe7ae67aeaadbfff880061c75728928de75d863"
integrity sha512-lSOhtgDy7jl74naVuwik54eCFD/oDiAhe1JV0uQVbm3O5tJKCTLqik+wSO9FvdjpZwLj/XwzA06NcJWM/PyFcA==
version "2.0.0-alpha.17"
resolved "https://registry.yarnpkg.com/@nimiq/core-web/-/core-web-2.0.0-alpha.17.tgz#4cdfeb896ed98879566b4a87846d6c6c17796121"
integrity sha512-mPKhhrLXE/sRdBMxiEWtokTy889tkPILHg14wBzVuCwarjuH6CGxLWY64G2Mr6+kRXJpL95s7/zvaaMeCE1b3A==
dependencies:
comlink "^4.4.1"
websocket "^1.0.34"

"@nimiq/[email protected]":
version "1.5.8"
Expand Down Expand Up @@ -5809,7 +5810,7 @@ webidl-conversions@^3.0.0:
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==

websocket@^1.0.32:
websocket@^1.0.32, websocket@^1.0.34:
version "1.0.34"
resolved "https://registry.yarnpkg.com/websocket/-/websocket-1.0.34.tgz#2bdc2602c08bf2c82253b730655c0ef7dcab3111"
integrity sha512-PRDso2sGwF6kM75QykIesBijKSVceR6jL2G8NGYyq2XrItNC2P5/qL5XeR056GhA+Ly7JMFvJb9I312mJfmqnQ==
Expand Down

0 comments on commit f5f3b1d

Please sign in to comment.