All files / src/trxTypes Delegate.ts

100% Statements 12/12
100% Branches 9/9
100% Functions 3/3
100% Lines 10/10
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 271x                 1x 306x 306x     306x 306x 303x       1x 607x       1x  
import { BaseTx } from './BaseTx';
 
export interface IDelegateTxAsset {
  delegate: {
    username: string;
    publicKey: string;
  };
}
 
export class DelegateTx extends BaseTx<IDelegateTxAsset> {
  public type: number = 2;
  public amount       = 0;
 
  constructor(asset?: IDelegateTxAsset) {
    super(asset);
    if (typeof(asset) !== 'undefined') {
      asset.delegate.username = asset.delegate.username.toLowerCase().trim();
    }
  }
 
  protected getChildBytes(skipSignature: boolean, skipSecondSign: boolean) {
    return this.asset &&
      this.asset.delegate &&
      this.asset.delegate.username ? Buffer.from(this.asset.delegate.username, 'utf8') : null;
  }
}