mirror of
https://github.com/Qortal/qortal-ui.git
synced 2025-07-31 14:11:45 +00:00
added create poll and vote qortalrequest actions
This commit is contained in:
103
crypto/api/transactions/polls/CreatePollTransaction.js
Normal file
103
crypto/api/transactions/polls/CreatePollTransaction.js
Normal file
@@ -0,0 +1,103 @@
|
||||
'use strict'
|
||||
import TransactionBase from '../TransactionBase.js'
|
||||
import { QORT_DECIMALS } from '../../constants.js'
|
||||
|
||||
export default class CreatePollTransaction extends TransactionBase {
|
||||
constructor() {
|
||||
super()
|
||||
this.type = 8
|
||||
this._options = []
|
||||
}
|
||||
|
||||
render(html) {
|
||||
return html`
|
||||
${this._votedialog3}
|
||||
<div style="background: #eee; padding: 8px; margin: 8px 0; border-radius: 5px;">
|
||||
<span style="color: #000;">${this._rPollName}</span>
|
||||
</div>
|
||||
${this._votedialog4}
|
||||
<div style="background: #eee; padding: 8px; margin: 8px 0; border-radius: 5px;">
|
||||
<span style="color: #000;">${this._rPollDesc}</span>
|
||||
</div>
|
||||
${this._votedialog5}
|
||||
<div style="background: #eee; padding: 8px; margin: 8px 0; border-radius: 5px;">
|
||||
<span style="color: #000;">${this._pollOptions.join(', ')}</span>
|
||||
</div>
|
||||
${this._votedialog6}
|
||||
`
|
||||
}
|
||||
|
||||
addOption(option) {
|
||||
const optionBytes = this.constructor.utils.stringtoUTF8Array(option);
|
||||
const optionLength = this.constructor.utils.int32ToBytes(optionBytes.length);
|
||||
this._options.push({ length: optionLength, bytes: optionBytes });
|
||||
}
|
||||
|
||||
set votedialog3(votedialog3) {
|
||||
this._votedialog3 = votedialog3
|
||||
}
|
||||
|
||||
set votedialog4(votedialog4) {
|
||||
this._votedialog4 = votedialog4
|
||||
}
|
||||
set votedialog5(votedialog5) {
|
||||
this._votedialog5 = votedialog5
|
||||
}
|
||||
set votedialog6(votedialog6) {
|
||||
this._votedialog6 = votedialog6
|
||||
}
|
||||
|
||||
set fee(fee) {
|
||||
this._fee = fee * QORT_DECIMALS
|
||||
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
|
||||
}
|
||||
|
||||
set ownerAddress(ownerAddress) {
|
||||
this._ownerAddress = ownerAddress instanceof Uint8Array ? ownerAddress : this.constructor.Base58.decode(ownerAddress)
|
||||
}
|
||||
|
||||
set rPollName(rPollName) {
|
||||
this._rPollName = rPollName
|
||||
this._rPollNameBytes = this.constructor.utils.stringtoUTF8Array(this._rPollName)
|
||||
this._rPollNameLength = this.constructor.utils.int32ToBytes(this._rPollNameBytes.length);
|
||||
|
||||
}
|
||||
|
||||
set rPollDesc(rPollDesc) {
|
||||
this._rPollDesc = rPollDesc
|
||||
this._rPollDescBytes = this.constructor.utils.stringtoUTF8Array(this._rPollDesc.toLocaleLowerCase())
|
||||
this._rPollDescLength = this.constructor.utils.int32ToBytes(this._rPollDescBytes.length)
|
||||
}
|
||||
|
||||
set rOptions(rOptions) {
|
||||
const optionsArray = rOptions[0].split(', ').map(opt => opt.trim());
|
||||
this._pollOptions = optionsArray
|
||||
for (let i = 0; i < optionsArray.length; i++) {
|
||||
this.addOption(optionsArray[i]);
|
||||
}
|
||||
|
||||
this._rNumberOfOptionsBytes = this.constructor.utils.int32ToBytes(optionsArray.length);
|
||||
}
|
||||
|
||||
|
||||
get params() {
|
||||
const params = super.params
|
||||
params.push(
|
||||
this._ownerAddress,
|
||||
this._rPollNameLength,
|
||||
this._rPollNameBytes,
|
||||
this._rPollDescLength,
|
||||
this._rPollDescBytes,
|
||||
this._rNumberOfOptionsBytes
|
||||
)
|
||||
// Push the dynamic options
|
||||
console.log('this._options', this._options)
|
||||
for (let i = 0; i < this._options.length; i++) {
|
||||
params.push(this._options[i].length, this._options[i].bytes);
|
||||
}
|
||||
|
||||
params.push(this._feeBytes);
|
||||
|
||||
return params
|
||||
}
|
||||
}
|
57
crypto/api/transactions/polls/VoteOnPollTransaction.js
Normal file
57
crypto/api/transactions/polls/VoteOnPollTransaction.js
Normal file
@@ -0,0 +1,57 @@
|
||||
'use strict'
|
||||
import TransactionBase from '../TransactionBase.js'
|
||||
import { QORT_DECIMALS } from '../../constants.js'
|
||||
|
||||
export default class VoteOnPollTransaction extends TransactionBase {
|
||||
constructor() {
|
||||
super()
|
||||
this.type = 9
|
||||
}
|
||||
|
||||
render(html) {
|
||||
return html`
|
||||
${this._votedialog1}
|
||||
<div style="background: #eee; padding: 8px; margin: 8px 0; border-radius: 5px;">
|
||||
<span style="color: #000;">${this._rPollName}</span>
|
||||
</div>
|
||||
${this._votedialog2}
|
||||
`
|
||||
}
|
||||
|
||||
set votedialog1(votedialog1) {
|
||||
this._votedialog1 = votedialog1
|
||||
}
|
||||
|
||||
set votedialog2(votedialog2) {
|
||||
this._votedialog2 = votedialog2
|
||||
}
|
||||
|
||||
set fee(fee) {
|
||||
this._fee = fee * QORT_DECIMALS
|
||||
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
|
||||
}
|
||||
|
||||
|
||||
set rPollName(rPollName) {
|
||||
this._rPollName = rPollName
|
||||
this._rPollNameBytes = this.constructor.utils.stringtoUTF8Array(this._rPollName)
|
||||
this._rPollNameLength = this.constructor.utils.int32ToBytes(this._rPollNameBytes.length)
|
||||
}
|
||||
|
||||
|
||||
set rOptionIndex(rOptionIndex) {
|
||||
this._rOptionIndex = rOptionIndex
|
||||
this._rOptionIndexBytes = this.constructor.utils.int32ToBytes(this._rOptionIndex)
|
||||
}
|
||||
|
||||
get params() {
|
||||
const params = super.params
|
||||
params.push(
|
||||
this._rPollNameLength,
|
||||
this._rPollNameBytes,
|
||||
this._rOptionIndexBytes,
|
||||
this._feeBytes
|
||||
)
|
||||
return params
|
||||
}
|
||||
}
|
@@ -23,6 +23,8 @@ import RewardShareTransaction from './reward-share/RewardShareTransaction.js'
|
||||
import RemoveRewardShareTransaction from './reward-share/RemoveRewardShareTransaction.js'
|
||||
import TransferPrivsTransaction from './TransferPrivsTransaction.js'
|
||||
import DeployAtTransaction from './DeployAtTransaction.js'
|
||||
import VoteOnPollTransaction from './polls/VoteOnPollTransaction.js'
|
||||
import CreatePollTransaction from './polls/CreatePollTransaction.js'
|
||||
|
||||
export const transactionTypes = {
|
||||
2: PaymentTransaction,
|
||||
@@ -31,6 +33,8 @@ export const transactionTypes = {
|
||||
5: SellNameTransacion,
|
||||
6: CancelSellNameTransacion,
|
||||
7: BuyNameTransacion,
|
||||
8: CreatePollTransaction,
|
||||
9: VoteOnPollTransaction,
|
||||
16: DeployAtTransaction,
|
||||
17: MessageTransaction,
|
||||
18: ChatTransaction,
|
||||
|
Reference in New Issue
Block a user