Skip to content

Commit

Permalink
Add transcoder for Register as validator transaction. Add support for…
Browse files Browse the repository at this point in the history
… approve component for this txn type
  • Loading branch information
Lazy Nina committed Jan 5, 2024
1 parent 7fdd79a commit 92fb5b3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/app/approve/approve.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
TransactionMetadataUpdateNFT,
TransactionMetadataUpdateProfile,
TransactionSpendingLimit,
TransactionMetadataRegisterAsValidator,
} from '../../lib/deso/transaction';
import { ExtraData } from '../../types/identity';
import { AccountService } from '../account.service';
Expand Down Expand Up @@ -588,6 +589,10 @@ export class ApproveComponent implements OnInit {
description = `unknown messaging action on ${messageType} to ${recipient}`;
}
break;
case TransactionMetadataRegisterAsValidator:
// TODO: Do we want any additional details in the approve component?
description = 'register as a validator';
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 @@ -35,6 +35,7 @@ import {
TransactionMetadataUpdateGlobalParams,
TransactionMetadataUpdateNFT,
TransactionMetadataUpdateProfile,
TransactionMetadataRegisterAsValidator,
} from '../lib/deso/transaction';
import { SwalHelper } from '../lib/helpers/swal-helper';
import { AccessLevel, PublicUserInfo } from '../types/identity';
Expand Down Expand Up @@ -518,6 +519,7 @@ export class IdentityService {
case TransactionMetadataDAOCoin:
case TransactionMetadataTransferDAOCoin:
case TransactionMetadataDAOCoinLimitOrder:
case TransactionMetadataRegisterAsValidator:
return AccessLevel.Full;

case TransactionMetadataFollow:
Expand Down
25 changes: 25 additions & 0 deletions src/lib/bindata/transcoders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@ export const VarBuffer: Transcoder<Buffer> = {
write: (bytes) => Buffer.concat([uvarint64ToBuf(bytes.length), bytes]),
};

export const VarBufferArray: Transcoder<Buffer[]> = {
read: (bytes) => {
let [count, buffer] = bufToUvarint64(bytes);

const result = [];
for (let i = 0; i < count; i++) {
let size;
[size, buffer] = bufToUvarint64(buffer);
result.push(buffer.slice(0, size));
buffer = buffer.slice(size);
}

return [result, buffer];
},
write: (buffers) => {
const count = uvarint64ToBuf(buffers.length);
return Buffer.concat([
count,
...buffers.map((buffer) =>
Buffer.concat([uvarint64ToBuf(buffer.length), buffer])
),
]);
},
};

export const TransactionNonceTranscoder: Transcoder<TransactionNonce | null> = {
read: (bytes) => {
return TransactionNonce.fromBytes(bytes) as [TransactionNonce, Buffer];
Expand Down
27 changes: 27 additions & 0 deletions src/lib/deso/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Uint8,
Uvarint64,
VarBuffer,
VarBufferArray,
} from '../bindata/transcoders';

export class TransactionInput extends BinaryRecord {
Expand Down Expand Up @@ -581,6 +582,31 @@ export class TransactionMetadataNewMessage extends BinaryRecord {
newMessageOperation: number = 0;
}

export class TransactionMetadataRegisterAsValidator extends TransactionMetadata {
@Transcode(VarBufferArray)
domains: Buffer[] = [];

@Transcode(Boolean)
disableDelegatedStake: boolean = false;

@Transcode(Uvarint64)
delegatedStakeCommissionBasisPoints: number = 0;

// TODO: Technically this is a bls public key,
// but under the hood it's really just a byte array.
// The challenge is converting this into something human
// readable in the UI.
@Transcode(VarBuffer)
votingPublicKey: Buffer = Buffer.alloc(0);

// TODO: Technically this is a bls signature,
// but under the hood it's really just a byte array.
// The challenge is converting this into something human
// readable in the UI.
@Transcode(VarBuffer)
votingAuthorization: Buffer = Buffer.alloc(0);
}

export const TransactionTypeMetadataMap = {
1: TransactionMetadataBlockReward,
2: TransactionMetadataBasicTransfer,
Expand Down Expand Up @@ -614,6 +640,7 @@ export const TransactionTypeMetadataMap = {
31: TransactionMetadataAccessGroup,
32: TransactionMetadataAccessGroupMembers,
33: TransactionMetadataNewMessage,
34: TransactionMetadataRegisterAsValidator,
};

export class Transaction extends BinaryRecord {
Expand Down

0 comments on commit 92fb5b3

Please sign in to comment.