Skip to content

Commit

Permalink
Add association transactions (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
svenstm authored Jan 30, 2020
1 parent e3e6ab7 commit 33c508c
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class BlockDetailsComponent implements OnInit {
case TransactionType.DATA:
case TransactionType.ANCHOR:
return 'Anchors';
case TransactionType.INVOKE_ASSOCIATION:
return 'Invoke association';
case TransactionType.REVOKE_ASSOCIATION:
return 'Revoke association';
}

return '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@
<div class="label">Amount</div>
<div class="value">{{ transaction.amount | lto | number }}</div>
</div>

<ng-container *ngIf="showAssocFields(transaction)">
<div class="item">
<div class="label">AssociationType</div>
<div class="value">{{ transaction.associationType | number }}</div>
</div>
<div class="item">
<div class="label">Party</div>
<div class="value">
<a [routerLink]="['/', 'addresses', transaction.party]">
<lto-responsive-text xs="25" sm="50" [text]="transaction.party"></lto-responsive-text>
</a>
<lto-clipboard-button [text]="transaction.party"></lto-clipboard-button>
</div>
</div>
</ng-container>
</mat-card-content>
</mat-card>

Expand Down Expand Up @@ -96,6 +112,12 @@ <h2>Hash {{ receipt.valid ? 'valid' : 'invalid' }}</h2>
</ng-container>
</ng-container>

<ng-container *ngIf="showAssocHash(transaction)">

<ng-container *ngTemplateOutlet="assocTpl; context: { $implicit: transaction }">
</ng-container>
</ng-container>

<ng-container *ngIf="transaction.type === TransactionType.MASS_TRANSFER">
<ng-container
*ngTemplateOutlet="transfersTpl; context: { $implicit: transaction }"
Expand Down Expand Up @@ -131,6 +153,34 @@ <h2>Hash {{ receipt.valid ? 'valid' : 'invalid' }}</h2>
</mat-card>
</ng-template>

<ng-template #assocTpl let-transaction>
<mat-card>
<mat-card-title>Hash</mat-card-title>
<mat-card-content>
<div class="hash">
<lto-responsive-text
xl="117"
lg="117"
md="100"
sm="63"
xs="33"
[text]="transaction.hash | encode: anchorsEncoding"
></lto-responsive-text>
</div>
</mat-card-content>
<mat-card-actions>
<button mat-button [matMenuTriggerFor]="encodingMenu">
{{ anchorsEncoding }} <mat-icon>arrow_drop_down</mat-icon>
</button>
<mat-menu #encodingMenu="matMenu">
<button mat-menu-item (click)="setAnchorsEncoding(Encoding.hex)">hex</button>
<button mat-menu-item (click)="setAnchorsEncoding(Encoding.base58)">base58</button>
<button mat-menu-item (click)="setAnchorsEncoding(Encoding.base64)">base64</button>
</mat-menu>
</mat-card-actions>
</mat-card>
</ng-template>

<ng-template #transfersTpl let-transaction>
<mat-card>
<mat-card-title>Transfers</mat-card-title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ export class TransactionDetailsComponent {
return false;
}

showAssocFields(transaction: Transaction): boolean {
switch (transaction.type) {
case TransactionType.INVOKE_ASSOCIATION:
case TransactionType.REVOKE_ASSOCIATION:
return true;
default:
return false;
}
}

showAssocHash(transaction: Transaction): boolean {
return (transaction.type === 16 || transaction.type === 17) && !!transaction.hash;
}

showRecipient(transaction: Transaction): boolean {
return transaction.type === 4 || transaction.type === 7;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export class TransactionLabelPipe implements PipeTransform {
return 'Data';
case TransactionType.ANCHOR:
return 'Anchor';
case TransactionType.INVOKE_ASSOCIATION:
return 'Invoke association';
case TransactionType.REVOKE_ASSOCIATION:
return 'Revoke association';
}
}
}
5 changes: 4 additions & 1 deletion libs/core/src/lib/lto-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ declare namespace LTO.API {
transactions: Transaction[];
}

export type TransactionType = 4 | 8 | 9 | 11 | 12 | 15;
export type TransactionType = 4 | 8 | 9 | 11 | 12 | 15 | 16 | 17;

export interface Transaction {
type: TransactionType;
Expand All @@ -54,6 +54,9 @@ declare namespace LTO.API {
signature?: string;
transfers?: Array<{ recipient: string; amount: number }>;
lease?: Transaction;
hash?: string;
associationType?: number;
party?: string;
}

export interface Stats {
Expand Down
4 changes: 3 additions & 1 deletion libs/core/src/lib/models/transaction-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export enum TransactionType {
CANCEL_LEASE = 9,
MASS_TRANSFER = 11,
DATA = 12,
ANCHOR = 15
ANCHOR = 15,
INVOKE_ASSOCIATION = 16,
REVOKE_ASSOCIATION = 17,
}
62 changes: 59 additions & 3 deletions libs/core/src/lib/models/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,18 @@ export abstract class Transaction {
return this._apiData.anchors || [];
}

get hash(): string {
return this._apiData.hash || '';
}

get party(): string {
return this._apiData.party || '';
}

get associationType(): number {
return this._apiData.associationType || 0;
}

protected constructor(protected _apiData: LTO.API.Transaction) {}

/**
Expand All @@ -75,14 +87,14 @@ export abstract class Transaction {
export class TransferTransaction extends Transaction {
readonly type = TransactionType.TRANSFER;
get signature(): string {
return this._apiData.signature || '';
return this._apiData.signature || this._apiData.proofs[0] || '';
}
}

export class LeaseTransaction extends Transaction {
readonly type = TransactionType.LEASE;
get signature(): string {
return this._apiData.signature || '';
return this._apiData.signature || this._apiData.proofs[0] || '';
}
}

Expand All @@ -94,7 +106,7 @@ export class CancelLeaseTransaction extends Transaction {
}

get signature(): string {
return this._apiData.signature || '';
return this._apiData.signature || this._apiData.proofs[0] || '';
}
}

Expand Down Expand Up @@ -146,6 +158,46 @@ export class AnchorTransaction extends Transaction {
}
}

export class InvokeAssociationTransaction extends Transaction {
readonly type = TransactionType.INVOKE_ASSOCIATION;

get hash(): string {
return this._apiData.hash || '';
}

get party(): string {
return this._apiData.party || '';
}

get associationType(): number {
return this._apiData.associationType || 0;
}

get signature(): string {
return this._apiData.proofs ? this._apiData.proofs[0] : '';
}
}

export class RevokeAssociationTransaction extends Transaction {
readonly type = TransactionType.REVOKE_ASSOCIATION;

get hash(): string {
return this._apiData.hash || '';
}

get party(): string {
return this._apiData.party || '';
}

get associationType(): number {
return this._apiData.associationType || 0;
}

get signature(): string {
return this._apiData.proofs ? this._apiData.proofs[0] : '';
}
}

function getConstructor(type: TransactionType) {
switch (type) {
case TransactionType.TRANSFER:
Expand All @@ -160,6 +212,10 @@ function getConstructor(type: TransactionType) {
return DataTransaction;
case TransactionType.ANCHOR:
return AnchorTransaction;
case TransactionType.INVOKE_ASSOCIATION:
return InvokeAssociationTransaction;
case TransactionType.REVOKE_ASSOCIATION:
return RevokeAssociationTransaction;
default:
throw new Error(`Uncnown transaction type ${type}`);
}
Expand Down

0 comments on commit 33c508c

Please sign in to comment.