-
Notifications
You must be signed in to change notification settings - Fork 62
/
AccountLinkTransaction.ts
114 lines (98 loc) · 3.74 KB
/
AccountLinkTransaction.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* Copyright 2019 NEM
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @module transactions/AccountLinkTransaction
*/
import { Convert as convert } from '../../core/format';
import AccountLinkTransactionBufferPackage from '../buffers/AccountLinkTransactionBuffer';
import AccountLinkTransactionSchema from '../schemas/AccountLinkTransactionSchema';
import {
VerifiableTransaction,
} from './VerifiableTransaction';
const {
flatbuffers,
} = require('flatbuffers');
const {
AccountLinkTransactionBuffer,
} = AccountLinkTransactionBufferPackage.Buffers;
export class AccountLinkTransaction extends VerifiableTransaction {
constructor(bytes) {
super(bytes, AccountLinkTransactionSchema);
}
}
// tslint:disable-next-line:max-classes-per-file
export class Builder {
fee: any;
version: any;
type: any;
deadline: any;
remoteAccountKey: any;
linkAction: any;
constructor() {
this.fee = [0, 0];
this.version = 36867;
this.type = 0x414C;
}
addFee(fee) {
this.fee = fee;
return this;
}
addVersion(version) {
this.version = version;
return this;
}
addType(type) {
this.type = type;
return this;
}
addDeadline(deadline) {
this.deadline = deadline;
return this;
}
addRemoteAccountKey(remoteAccountKey) {
this.remoteAccountKey = convert.hexToUint8(remoteAccountKey);
return this;
}
addLinkAction(linkAction) {
this.linkAction = linkAction;
return this;
}
build() {
const builder = new flatbuffers.Builder(1);
// Create vectors
const signatureVector = AccountLinkTransactionBuffer
.createSignatureVector(builder, Array(...Array(64)).map(Number.prototype.valueOf, 0));
const signerVector = AccountLinkTransactionBuffer.createSignerVector(builder, Array(...Array(32)).map(Number.prototype.valueOf, 0));
const deadlineVector = AccountLinkTransactionBuffer.createDeadlineVector(builder, this.deadline);
const feeVector = AccountLinkTransactionBuffer.createFeeVector(builder, this.fee);
const remoteAccountKeyVector = AccountLinkTransactionBuffer.createRemoteAccountKeyVector(builder, this.remoteAccountKey);
AccountLinkTransactionBuffer.startAccountLinkTransactionBuffer(builder);
AccountLinkTransactionBuffer.addSize(builder, 153);
AccountLinkTransactionBuffer.addSignature(builder, signatureVector);
AccountLinkTransactionBuffer.addSigner(builder, signerVector);
AccountLinkTransactionBuffer.addVersion(builder, this.version);
AccountLinkTransactionBuffer.addType(builder, this.type);
AccountLinkTransactionBuffer.addFee(builder, feeVector);
AccountLinkTransactionBuffer.addDeadline(builder, deadlineVector);
AccountLinkTransactionBuffer.addRemoteAccountKey(builder, remoteAccountKeyVector);
AccountLinkTransactionBuffer.addLinkAction(builder, this.linkAction);
// Calculate size
const codedTransfer = AccountLinkTransactionBuffer.endAccountLinkTransactionBuffer(builder);
builder.finish(codedTransfer);
const bytes = builder.asUint8Array();
return new AccountLinkTransaction(bytes);
}
}