|
| 1 | +import { |
| 2 | + BaseAddress, |
| 3 | + BaseKey, |
| 4 | + BaseTransactionBuilder, |
| 5 | + BuildTransactionError, |
| 6 | + FeeOptions, |
| 7 | + PublicKey as BasePublicKey, |
| 8 | + Signature, |
| 9 | + TransactionType, |
| 10 | +} from '@bitgo/sdk-core'; |
| 11 | +import { Transaction } from './transaction'; |
| 12 | +import utils from './utils'; |
| 13 | +import BigNumber from 'bignumber.js'; |
| 14 | + |
| 15 | +export abstract class TransactionBuilder extends BaseTransactionBuilder { |
| 16 | + protected _transaction: Transaction; |
| 17 | + private _signatures: Signature[] = []; |
| 18 | + |
| 19 | + // get and set region |
| 20 | + /** |
| 21 | + * The transaction type. |
| 22 | + */ |
| 23 | + protected abstract get transactionType(): TransactionType; |
| 24 | + |
| 25 | + /** @inheritdoc */ |
| 26 | + protected get transaction(): Transaction { |
| 27 | + return this._transaction; |
| 28 | + } |
| 29 | + |
| 30 | + /** @inheritdoc */ |
| 31 | + protected set transaction(transaction: Transaction) { |
| 32 | + this._transaction = transaction; |
| 33 | + } |
| 34 | + |
| 35 | + /** @inheritdoc */ |
| 36 | + protected signImplementation(key: BaseKey): Transaction { |
| 37 | + throw new Error('Method not implemented.'); |
| 38 | + } |
| 39 | + |
| 40 | + /** @inheritDoc */ |
| 41 | + addSignature(publicKey: BasePublicKey, signature: Buffer): void { |
| 42 | + this._signatures.push({ publicKey, signature }); |
| 43 | + } |
| 44 | + |
| 45 | + /** |
| 46 | + * Sets the sender of this transaction. |
| 47 | + * This account will be responsible for paying transaction fees. |
| 48 | + * |
| 49 | + * @param {string} senderAddress the account that is sending this transaction |
| 50 | + * @returns {TransactionBuilder} This transaction builder |
| 51 | + */ |
| 52 | + sender(senderAddress: string): this { |
| 53 | + throw new Error('Method not implemented.'); |
| 54 | + } |
| 55 | + |
| 56 | + fee(feeOptions: FeeOptions): this { |
| 57 | + throw new Error('Method not implemented.'); |
| 58 | + } |
| 59 | + |
| 60 | + /** @inheritdoc */ |
| 61 | + protected fromImplementation(rawTransaction: string): Transaction { |
| 62 | + throw new Error('Method not implemented.'); |
| 63 | + } |
| 64 | + |
| 65 | + /** @inheritdoc */ |
| 66 | + protected async buildImplementation(): Promise<Transaction> { |
| 67 | + throw new Error('Method not implemented.'); |
| 68 | + } |
| 69 | + |
| 70 | + // region Validators |
| 71 | + /** @inheritdoc */ |
| 72 | + validateAddress(address: BaseAddress, addressFormat?: string): void { |
| 73 | + if (!utils.isValidAddress(address.address)) { |
| 74 | + throw new BuildTransactionError('Invalid address ' + address.address); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + /** @inheritdoc */ |
| 79 | + validateKey(key: BaseKey): void { |
| 80 | + throw new Error('Method not implemented.'); |
| 81 | + } |
| 82 | + |
| 83 | + /** @inheritdoc */ |
| 84 | + validateRawTransaction(rawTransaction: string): void { |
| 85 | + throw new Error('Method not implemented.'); |
| 86 | + } |
| 87 | + |
| 88 | + /** @inheritdoc */ |
| 89 | + validateTransaction(transaction?: Transaction): void { |
| 90 | + throw new Error('Method not implemented.'); |
| 91 | + } |
| 92 | + |
| 93 | + /** @inheritdoc */ |
| 94 | + validateValue(value: BigNumber): void { |
| 95 | + if (value.isLessThan(0)) { |
| 96 | + throw new BuildTransactionError('Value cannot be less than zero'); |
| 97 | + } |
| 98 | + } |
| 99 | +} |
0 commit comments