Options
All
  • Public
  • Public/Protected
  • All
Menu

Class QVoteZilliqa

Hierarchy

  • Core
    • QVoteZilliqa

Index

Constructors

constructor

  • new QVoteZilliqa(zil?: Zilliqa, protocol?: { chainId: number; msgVersion: number }, secondsPerTxBlockAverage?: number): QVoteZilliqa
  • Parameters

    • Optional zil: Zilliqa
    • protocol: { chainId: number; msgVersion: number } = ...

      the chain id and the message version of the used blockchain

      • chainId: number
      • msgVersion: number
    • secondsPerTxBlockAverage: number = 60

      the seconds on average it takes for a new transaction block to be created

    Returns QVoteZilliqa

Properties

Protected VERSION

VERSION: number

Protected code

code: string

Protected secondsPerTxBlockAverage

secondsPerTxBlockAverage: number

Protected zil

zil: undefined | Zilliqa

Methods

Protected createValueParam

  • createValueParam(type: All, vname: string, value: ValueField): Value
  • Parameters

    • type: All
    • vname: string
    • value: ValueField

    Returns Value

deploy

  • deploy(payload: QVDeployPayload, ownerAddress: string, options?: { gasLimit?: Long; gasPrice?: BN }): Promise<[string, Contract, Transaction]>
  • example

    const [qvotingAddress, qvInstance, deployTx] = await qv.deploy( { name: "Test hi", description: "Hello hi", options: ["opt1", "opt2", "opt3", "opt4"], creditToTokenRatio: "1000", //can register for next 0 min registrationEndTime: qv.futureTxBlockNumber(curBlockNumber, 60 * 0), //can vote in 0 min and voting is open for 15 min expirationBlock: qv.futureTxBlockNumber(curBlockNumber, 60 * 15), tokenId: "DogeCoinZilToken", }, deployerAddress );

    Parameters

    • payload: QVDeployPayload

      the deploy payload for the contract

    • ownerAddress: string

      the address of the owner of the contract

    • options: { gasLimit?: Long; gasPrice?: BN } = ...

      optional gas price and gas limit for the deploy

      • Optional gasLimit?: Long
      • Optional gasPrice?: BN

    Returns Promise<[string, Contract, Transaction]>

    the address the contract instance and the confirmed transaction

futureTxBlockNumber

  • futureTxBlockNumber(blockNumber: number, secondsToAdd: number): string
  • example

    const txblock = await zil.blockchain.getLatestTxBlock(); const curBlockNumber = parseInt(txblock.result.header.BlockNum); // approx blocknumber 60 seconds into the future const futureBlockNumber = qv.futureTxBlockNumber(curBlockNumber, 60);

    Parameters

    • blockNumber: number

      the current block number of the blockchain

    • secondsToAdd: number

      seconds to add to the blocknumber to receive a block number that will be the current one x seconds in the future

    Returns string

Protected getCallParamsPayload

  • getCallParamsPayload(__namedParameters: { amount: number; gasLimit?: Long; gasPrice: BN }): [{ amount: BN; gasLimit: Long; gasPrice: BN; version: number }, number, number, boolean]
  • Parameters

    • __namedParameters: { amount: number; gasLimit?: Long; gasPrice: BN }
      • amount: number
      • Optional gasLimit?: Long
      • gasPrice: BN

    Returns [{ amount: BN; gasLimit: Long; gasPrice: BN; version: number }, number, number, boolean]

Protected getConfirmedTx

  • getConfirmedTx(tx: Transaction): Promise<Transaction>
  • Parameters

    • tx: Transaction

    Returns Promise<Transaction>

getContractState

  • getContractState(address: string, maxRetries?: number, intervalMs?: number): Promise<QVState>
  • example

    const qvState = await qv.getContractState(address1, 14);

    Parameters

    • address: string

      the address of the contract to read state off

    • maxRetries: number = 6

      optional max number of retries to call the blockchain

    • intervalMs: number = 750

      optional interval in which the retries increase lineraly with

    Returns Promise<QVState>

    the state of the qvote contract

Protected getGasPriceAndLimit

  • getGasPriceAndLimit(__namedParameters: { gasLimit?: Long; gasPrice?: BN }): Promise<{ gasLimit: Long; gasPrice: BN }>
  • Parameters

    • __namedParameters: { gasLimit?: Long; gasPrice?: BN }
      • Optional gasLimit?: Long
      • Optional gasPrice?: BN

    Returns Promise<{ gasLimit: Long; gasPrice: BN }>

getInstance

  • getInstance(contractAddress: string): Contract
  • Parameters

    • contractAddress: string

      the address of a deployed qv or queue contract

    Returns Contract

    the instance of that contract

Protected getZil

  • getZil(): Zilliqa

getZilPay

  • getZilPay(): Promise<any>
  • webonly
    webonly
    webonly
    webonly
    example

    const provider = await qv.connectAndGetZilPayProvider(); const zil = new Zilliqa("", provider);

    Returns Promise<any>

handleDeploy

  • handleDeploy(promise: Promise<[Transaction, Contract]>): Promise<[string, Contract, Transaction]>
  • example

    const [address, instance, deployTx] = await qv.handleDeploy( contract.deploy(...qv.payloadDeploy({ gasPrice })) );

    Parameters

    • promise: Promise<[Transaction, Contract]>

      that is returned from the zil sdk

    Returns Promise<[string, Contract, Transaction]>

handleMinGas

  • handleMinGas(promise: Promise<RPCResponse<string, string>>): Promise<BN>
  • example

    const gasPrice = await qv.handleMinGas(zil.blockchain.getMinimumGasPrice());

    Parameters

    • promise: Promise<RPCResponse<string, string>>

      that is returned from the zil sdk

    Returns Promise<BN>

ownerRegister

  • ownerRegister(qvInstance: Contract, payload: { addresses: string[]; creditsForAddresses: number[] }, options?: { gasLimit?: Long; gasPrice?: BN }): Promise<Transaction>
  • example

    const registerTx = await qv.ownerRegister(qvInstance, { addresses: [deployerAddress, voterAddress], creditsForAddresses: [100, 100], });

    Parameters

    • qvInstance: Contract

      the instance of the contract to be called

    • payload: { addresses: string[]; creditsForAddresses: number[] }

      the addresses to be registered and the credits for those addresses

      • addresses: string[]
      • creditsForAddresses: number[]
    • options: { gasLimit?: Long; gasPrice?: BN } = ...

      optional gas price and gas limit for the deploy

      • Optional gasLimit?: Long
      • Optional gasPrice?: BN

    Returns Promise<Transaction>

    the confirmed transaction

parseInitAndState

  • parseInitAndState(init: Value[], state: {}): QVState
  • description

    Converts the raw init and mutable state of the QV contract into a more approachable js object divides the votes for each option by 100 to get the actual value populates unvoted options with 0 strips away the wrapper for states

    example

    const init = await contractInstance.getInit(); const state = await contractInstance.getState(); const contractState = qv.parseInitAndState(init, state);

    Parameters

    • init: Value[]

      The immutable state of the contract

    • state: {}

      The mutable state of the contract

      • [key: string]: any

    Returns QVState

payloadDeploy

  • payloadDeploy(__namedParameters: { gasLimit?: Long; gasPrice: BN }): DeployPayload
  • description

    Payload used to deploy contracts

    example

    const gasPrice = await qv.handleMinGas(zil.blockchain.getMinimumGasPrice()); contractInstance.deploy(...qv.payloadDeploy({ gasPrice }));

    Parameters

    • __namedParameters: { gasLimit?: Long; gasPrice: BN }
      • Optional gasLimit?: Long
      • gasPrice: BN

    Returns DeployPayload

payloadOwnerRegister

  • payloadOwnerRegister(__namedParameters: ContractCall<{ addresses: string[]; creditsForAddresses: number[] }>): CallPayload
  • description

    Payload to make a contract call to the owner register function It allows the owner to register a list of addresses with corresponding number of credits for each address as the balance

    example

    const registerTx = await instance.call(...qv.payloadOwnerRegister({ payload: { addresses: [deployerAddress, voterAddress], creditsForAddresses: [100, 100] }, gasPrice }));

    Parameters

    • __namedParameters: ContractCall<{ addresses: string[]; creditsForAddresses: number[] }>

    Returns CallPayload

payloadQv

  • payloadQv(__namedParameters: { ownerAddress: string; payload: QVDeployPayload }): ContractPayload
  • description

    Payload that allows to create a contract factory instance

    example

    const registerEnd = qv.futureTxBlockNumber(curBlockNumber, 60 * 5); const end = qv.futureTxBlockNumber(curBlockNumber, 60 * 15); const contract = zil.contracts.new(...qv.payloadQv({ payload: { name: "Test hi", description: "Hello hi", options: ["opt1", "opt2", "opt3", "opt4"], creditToTokenRatio: "1000", //can register for next 5 min registrationEndTime: registerEnd, //can vote in 5 min and voting is open for 10 min expirationBlock: end, tokenId: "DogeCoinZilToken" }, ownerAddress: deployerAddress, }));

    Parameters

    • __namedParameters: { ownerAddress: string; payload: QVDeployPayload }
      • ownerAddress: string
      • payload: QVDeployPayload

    Returns ContractPayload

payloadRegister

  • payloadRegister(__namedParameters: { amount?: number; gasLimit?: Long; gasPrice: BN }): CallPayload
  • description

    Payload to make a contract call to the register function it registers the sender in a waiting list on the contract

    example

    const registerTx1 = await instance.call(...qv.payloadRegister({ gasPrice }));

    Parameters

    • __namedParameters: { amount?: number; gasLimit?: Long; gasPrice: BN }
      • Optional amount?: number
      • Optional gasLimit?: Long
      • gasPrice: BN

    Returns CallPayload

payloadVote

  • payloadVote(__namedParameters: ContractCall<{ creditsToOption: string[] }>): CallPayload
  • description

    Payload to make a contract call to the vote function it takes a list of credits that by index correspond to the options on the contract

    example

    const voteTx1 = await instance.call(...qv.payloadVote({ payload: { // ["opt1", "opt2", "opt3", "opt4"] so we are giving // 20 cred to opt1, and -80 to opt2 0 to opt3, 0 to opt4 creditsToOption: ["20", "-80", "0", "0"] }, gasPrice }));

    Parameters

    • __namedParameters: ContractCall<{ creditsToOption: string[] }>

    Returns CallPayload

Protected retryLoop

  • retryLoop(maxRetries: number, intervalMs: number, func: () => Promise<RPCResponse<Value[], any>>): Promise<[undefined | Value[], any]>
  • Parameters

    • maxRetries: number
    • intervalMs: number
    • func: () => Promise<RPCResponse<Value[], any>>
        • (): Promise<RPCResponse<Value[], any>>
        • Returns Promise<RPCResponse<Value[], any>>

    Returns Promise<[undefined | Value[], any]>

Protected stripInit

  • stripInit(init: Value[]): {}
  • Parameters

    • init: Value[]

    Returns {}

    • [key: string]: any

vote

  • vote(qvInstance: Contract, payload: { creditsToOption: string[] }, options?: { gasLimit?: Long; gasPrice?: BN }): Promise<Transaction>
  • example

    const registerTx = await qv.ownerRegister(qvInstance, { addresses: [deployerAddress, voterAddress], creditsForAddresses: [100, 100], });

    Parameters

    • qvInstance: Contract

      the instance of the contract to vote on

    • payload: { creditsToOption: string[] }

      the credits to option array

      • creditsToOption: string[]
    • options: { gasLimit?: Long; gasPrice?: BN } = ...

      optional gas price and gas limit for the deploy

      • Optional gasLimit?: Long
      • Optional gasPrice?: BN

    Returns Promise<Transaction>

    the confirmed transaction

Generated using TypeDoc