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 fbc96ba commit 0713d8d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/app/approve/approve.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
TransactionMetadataUpdateGlobalParams,
TransactionMetadataUpdateNFT,
TransactionMetadataUpdateProfile,
TransactionSpendingLimit,
TransactionSpendingLimit, TransactionMetadataRegisterAsValidator,
} from '../../lib/deso/transaction';
import { ExtraData } from '../../types/identity';
import { AccountService } from '../account.service';
Expand Down Expand Up @@ -588,6 +588,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
3 changes: 2 additions & 1 deletion src/app/identity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
TransactionMetadataUpdateBitcoinUSDExchangeRate,
TransactionMetadataUpdateGlobalParams,
TransactionMetadataUpdateNFT,
TransactionMetadataUpdateProfile,
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 +518,7 @@ export class IdentityService {
case TransactionMetadataDAOCoin:
case TransactionMetadataTransferDAOCoin:
case TransactionMetadataDAOCoinLimitOrder:
case TransactionMetadataRegisterAsValidator:
return AccessLevel.Full;

case TransactionMetadataFollow:
Expand Down
34 changes: 34 additions & 0 deletions src/lib/bindata/transcoders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,40 @@ 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 VarBufferSerializable: Serializable & Deserializable<Buffer> = {
// toBytes: () => {
// let buffer = Buffer.alloc(0);
// VarBuffer.write(buffer);
// return buffer;
// },
// fromBytes: (bytes) => {
// let [size, buffer] = bufToUvarint64(bytes);
// return [buffer.slice(0, size), buffer.slice(size)];
// },
// }

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

export class TransactionInput extends BinaryRecord {
Expand Down Expand Up @@ -581,6 +581,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 +639,7 @@ export const TransactionTypeMetadataMap = {
31: TransactionMetadataAccessGroup,
32: TransactionMetadataAccessGroupMembers,
33: TransactionMetadataNewMessage,
34: TransactionMetadataRegisterAsValidator,
};

export class Transaction extends BinaryRecord {
Expand Down

0 comments on commit 0713d8d

Please sign in to comment.