opnet
Version:
The perfect library for building Bitcoin-based applications.
45 lines (44 loc) • 1.84 kB
JavaScript
import { Address } from '@btc-vision/transaction';
export class ContractData {
contractAddress;
contractPublicKey;
bytecode;
wasCompressed;
deployedTransactionId;
deployedTransactionHash;
deployerPubKey;
deployerHashedPublicKey;
contractSeed;
contractSaltHash;
deployerAddress;
constructor(raw) {
this.contractAddress = raw.contractAddress;
this.contractPublicKey = Buffer.isBuffer(raw.contractPublicKey)
? new Address(raw.contractPublicKey)
: new Address(Buffer.from(raw.contractPublicKey, 'base64'));
this.bytecode = Buffer.isBuffer(raw.bytecode)
? raw.bytecode
: Buffer.from(raw.bytecode, 'base64');
this.wasCompressed = raw.wasCompressed;
this.deployedTransactionId = raw.deployedTransactionId;
this.deployedTransactionHash = raw.deployedTransactionHash;
this.deployerPubKey = Buffer.isBuffer(raw.deployerPubKey)
? raw.deployerPubKey
: Buffer.from(raw.deployerPubKey, 'base64');
this.deployerHashedPublicKey = Buffer.isBuffer(raw.deployerAddress)
? raw.deployerAddress
: Buffer.from(raw.deployerAddress.replace('0x', ''), 'base64');
this.contractSeed = Buffer.isBuffer(raw.contractSeed)
? raw.contractSeed
: Buffer.from(raw.contractSeed, 'base64');
this.contractSaltHash = Buffer.isBuffer(raw.contractSaltHash)
? raw.contractSaltHash
: Buffer.from(raw.contractSaltHash, 'base64');
if (this.deployerHashedPublicKey && this.deployerPubKey) {
this.deployerAddress = new Address(this.deployerHashedPublicKey, this.deployerPubKey);
}
else {
throw new Error('Deployer address or public key is missing');
}
}
}