2023-01-13 09:52:14 +01:00
|
|
|
'use strict'
|
2022-03-26 01:37:41 -07:00
|
|
|
import publicKeyToAddress from '../../wallet/publicKeyToAddress.js'
|
2021-12-25 14:39:47 +01:00
|
|
|
import TransactionBase from "../TransactionBase.js"
|
|
|
|
import nacl from '../../deps/nacl-fast.js'
|
|
|
|
import ed2curve from '../../deps/ed2curve.js'
|
2023-11-05 14:30:07 +01:00
|
|
|
import {Sha256} from 'asmcrypto.js'
|
|
|
|
import {DYNAMIC_FEE_TIMESTAMP} from '../../constants.js'
|
2021-12-25 14:39:47 +01:00
|
|
|
|
|
|
|
export default class RewardShareTransaction extends TransactionBase {
|
2023-01-13 09:52:14 +01:00
|
|
|
constructor() {
|
|
|
|
super()
|
|
|
|
this.type = 38
|
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
render(html) {
|
|
|
|
return html`
|
2023-11-05 14:30:07 +01:00
|
|
|
${this._rewarddialog1} <strong>${this._percentageShare / 1e8}%</strong> ${this._rewarddialog2} <strong>${this.constructor.Base58.encode(this._recipient)}</strong>?
|
2023-01-13 09:52:14 +01:00
|
|
|
${this._rewarddialog3}
|
|
|
|
<div style="background: #eee; padding: 8px; margin: 8px 0; border-radius: 5px;">
|
|
|
|
<span style="color: #000;">${this._base58RewardShareSeed}</span>
|
|
|
|
</div>
|
|
|
|
${this._rewarddialog4}
|
|
|
|
`
|
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
set rewarddialog1(rewarddialog1) {
|
|
|
|
this._rewarddialog1 = rewarddialog1
|
|
|
|
}
|
2022-04-22 14:49:16 +02:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
set rewarddialog2(rewarddialog2) {
|
|
|
|
this._rewarddialog2 = rewarddialog2
|
|
|
|
}
|
2022-04-22 14:49:16 +02:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
set rewarddialog3(rewarddialog3) {
|
|
|
|
this._rewarddialog3 = rewarddialog3
|
|
|
|
}
|
2022-04-22 14:49:16 +02:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
set rewarddialog4(rewarddialog4) {
|
|
|
|
this._rewarddialog4 = rewarddialog4
|
|
|
|
}
|
2022-04-22 14:49:16 +02:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
set recipientPublicKey(recipientPublicKey) {
|
|
|
|
this._base58RecipientPublicKey = recipientPublicKey instanceof Uint8Array ? this.constructor.Base58.encode(recipientPublicKey) : recipientPublicKey
|
|
|
|
this._recipientPublicKey = this.constructor.Base58.decode(this._base58RecipientPublicKey)
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
this.recipient = publicKeyToAddress(this._recipientPublicKey)
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
this.fee = (recipientPublicKey === this.constructor.Base58.encode(this._keyPair.publicKey) ? 0 : 0.001)
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
const convertedPrivateKey = ed2curve.convertSecretKey(this._keyPair.privateKey)
|
|
|
|
const convertedPublicKey = ed2curve.convertPublicKey(this._recipientPublicKey)
|
|
|
|
const sharedSecret = new Uint8Array(32);
|
|
|
|
nacl.lowlevel.crypto_scalarmult(sharedSecret, convertedPrivateKey, convertedPublicKey);
|
|
|
|
this._rewardShareSeed = new Sha256().process(sharedSecret).finish().result
|
|
|
|
this._base58RewardShareSeed = this.constructor.Base58.encode(this._rewardShareSeed)
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
this._rewardShareKeyPair = nacl.sign.keyPair.fromSeed(this._rewardShareSeed)
|
2023-08-13 14:39:32 +02:00
|
|
|
|
|
|
|
if (new Date(this._timestamp).getTime() >= DYNAMIC_FEE_TIMESTAMP) {
|
|
|
|
this.fee = (recipientPublicKey === this.constructor.Base58.encode(this._keyPair.publicKey) ? 0 : 0.01)
|
|
|
|
} else {
|
|
|
|
this.fee = (recipientPublicKey === this.constructor.Base58.encode(this._keyPair.publicKey) ? 0 : 0.001)
|
|
|
|
}
|
2023-01-13 09:52:14 +01:00
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
set recipient(recipient) {
|
|
|
|
this._recipient = recipient instanceof Uint8Array ? recipient : this.constructor.Base58.decode(recipient)
|
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
set percentageShare(share) {
|
|
|
|
this._percentageShare = share * 100
|
|
|
|
this._percentageShareBytes = this.constructor.utils.int64ToBytes(this._percentageShare)
|
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
|
2023-01-13 09:52:14 +01:00
|
|
|
get params() {
|
|
|
|
const params = super.params
|
|
|
|
params.push(
|
|
|
|
this._recipient,
|
|
|
|
this._rewardShareKeyPair.publicKey,
|
|
|
|
this._percentageShareBytes,
|
|
|
|
this._feeBytes
|
|
|
|
)
|
|
|
|
return params
|
|
|
|
}
|
2021-12-25 14:39:47 +01:00
|
|
|
}
|