Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transcoder for Unstake txn type. Add support for approve component for this new txn type. #294

Closed
wants to merge 1 commit into from
Closed
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
13 changes: 13 additions & 0 deletions src/app/approve/approve.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
TransactionMetadataRegisterAsValidator,
TransactionMetadataUnregisterAsValidator,
TransactionMetadataStake,
TransactionMetadataUnstake,
} from '../../lib/deso/transaction';
import { ExtraData } from '../../types/identity';
import { AccountService } from '../account.service';
Expand Down Expand Up @@ -610,6 +611,18 @@ export class ApproveComponent implements OnInit {
);
description = `stake ${stakeAmountNanos} $DESO to ${stakeValidatorPublicKey}`;
break;
case TransactionMetadataUnstake:
const unstakeMetadata = this.transaction
.metadata as TransactionMetadataUnstake;
const unstakeValidatorPublicKey = this.base58KeyCheck(
unstakeMetadata.validatorPublicKey
);
publicKeys = [unstakeValidatorPublicKey];
const unstakeAmountNanos = this.hexNanosToUnitString(
unstakeMetadata.unstakeAmountNanos
);
description = `unstake ${unstakeAmountNanos} $DESO from ${unstakeValidatorPublicKey}`;
break;
}

// Set the transaction description based on the description populated with public keys.
Expand Down
2 changes: 2 additions & 0 deletions src/app/identity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
TransactionMetadataRegisterAsValidator,
TransactionMetadataUnregisterAsValidator,
TransactionMetadataStake,
TransactionMetadataUnstake,
} from '../lib/deso/transaction';
import { SwalHelper } from '../lib/helpers/swal-helper';
import { AccessLevel, PublicUserInfo } from '../types/identity';
Expand Down Expand Up @@ -524,6 +525,7 @@ export class IdentityService {
case TransactionMetadataRegisterAsValidator:
case TransactionMetadataUnregisterAsValidator:
case TransactionMetadataStake:
case TransactionMetadataUnstake:
return AccessLevel.Full;

case TransactionMetadataFollow:
Expand Down
10 changes: 10 additions & 0 deletions src/lib/deso/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,15 @@ export class TransactionMetadataStake extends TransactionMetadata {
stakeAmountNanos: Buffer = Buffer.alloc(0);
}

export class TransactionMetadataUnstake extends TransactionMetadata {
@Transcode(VarBuffer)
validatorPublicKey: Buffer = Buffer.alloc(0);

// TODO: We may want a better way to handle uint256s.
@Transcode(BoolOptional(VarBuffer))
unstakeAmountNanos: Buffer = Buffer.alloc(0);
}

export const TransactionTypeMetadataMap = {
1: TransactionMetadataBlockReward,
2: TransactionMetadataBasicTransfer,
Expand Down Expand Up @@ -658,6 +667,7 @@ export const TransactionTypeMetadataMap = {
34: TransactionMetadataRegisterAsValidator,
35: TransactionMetadataUnregisterAsValidator,
36: TransactionMetadataStake,
37: TransactionMetadataUnstake,
};

export class Transaction extends BinaryRecord {
Expand Down
Loading