Browse Source

Fixx transactions

pull/91/head
AlphaX-Projects 2 years ago
parent
commit
6049d18f49
  1. 47
      qortal-ui-crypto/api/transactions/TransactionBase.js
  2. 220
      qortal-ui-crypto/api/transactions/chat/ChatBase.js
  3. 2
      qortal-ui-crypto/api/transactions/chat/ChatTransaction.js
  4. 3
      qortal-ui-crypto/api/transactions/chat/GroupChatTransaction.js

47
qortal-ui-crypto/api/transactions/TransactionBase.js

@ -19,6 +19,53 @@ export default class TransactionBase {
this.fee = 0 this.fee = 0
this.groupID = 0 this.groupID = 0
this.timestamp = Date.now() this.timestamp = Date.now()
this.tests = [
() => {
if (!(this._type >= 1 && this._type in TX_TYPES)) {
return 'Invalid type: ' + this.type
}
return true
},
() => {
if (this._fee < 0) {
return 'Invalid fee: ' + this._fee / QORT_DECIMALS
}
return true
},
() => {
if (this._groupID < 0 || !Number.isInteger(this._groupID)) {
return 'Invalid groupID: ' + this._groupID
}
return true
},
() => {
if (!(new Date(this._timestamp)).getTime() > 0) {
return 'Invalid timestamp: ' + this._timestamp
}
return true
},
() => {
if (!(this._lastReference instanceof Uint8Array && this._lastReference.byteLength == 64)) {
if (this._lastReference == 0) {
return 'Invalid last reference. Please ensure that you have at least 0.001 QORT for the transaction fee.'
}
return 'Invalid last reference: ' + this._lastReference
}
return true
},
() => {
if (!(this._keyPair)) {
return 'keyPair must be specified'
}
if (!(this._keyPair.publicKey instanceof Uint8Array && this._keyPair.publicKey.byteLength === 32)) {
return 'Invalid publicKey'
}
if (!(this._keyPair.privateKey instanceof Uint8Array && this._keyPair.privateKey.byteLength === 64)) {
return 'Invalid privateKey'
}
return true
}
]
} }
render(html) { render(html) {

220
qortal-ui-crypto/api/transactions/chat/ChatBase.js

@ -5,93 +5,137 @@ import Base58 from '../../deps/Base58.js'
import utils from '../../deps/utils.js' import utils from '../../deps/utils.js'
export default class ChatBase { export default class ChatBase {
static get utils() { static get utils() {
return utils return utils
} }
static get nacl() { static get nacl() {
return nacl return nacl
} }
static get Base58() { static get Base58() {
return Base58 return Base58
} }
constructor() { constructor() {
this.fee = 0 this.fee = 0
this.groupID = 0 this.groupID = 0
} this.tests = [
() => {
set keyPair(keyPair) { if (!(this._type >= 1 && this._type in TX_TYPES)) {
this._keyPair = keyPair return 'Invalid type: ' + this.type
} }
return true
set type(type) { },
this.typeText = TX_TYPES[type] () => {
this._type = type if (this._fee < 0) {
this._typeBytes = this.constructor.utils.int32ToBytes(this._type) return 'Invalid fee: ' + this._fee / QORT_DECIMALS
} }
return true
set groupID(groupID) { },
this._groupID = groupID () => {
this._groupIDBytes = this.constructor.utils.int32ToBytes(this._groupID) if (this._groupID < 0 || !Number.isInteger(this._groupID)) {
} return 'Invalid groupID: ' + this._groupID
}
set timestamp(timestamp) { return true
this._timestamp = timestamp },
this._timestampBytes = this.constructor.utils.int64ToBytes(this._timestamp) () => {
} if (!(new Date(this._timestamp)).getTime() > 0) {
return 'Invalid timestamp: ' + this._timestamp
set fee(fee) { }
this._fee = fee * QORT_DECIMALS return true
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee) },
} () => {
if (!(this._lastReference instanceof Uint8Array && this._lastReference.byteLength == 64)) {
set lastReference(lastReference) { return 'Invalid last reference: ' + this._lastReference
this._lastReference = lastReference instanceof Uint8Array ? lastReference : this.constructor.Base58.decode(lastReference) }
} return true
},
get params() { () => {
return [ if (!(this._keyPair)) {
this._typeBytes, return 'keyPair must be specified'
this._timestampBytes, }
this._groupIDBytes, if (!(this._keyPair.publicKey instanceof Uint8Array && this._keyPair.publicKey.byteLength === 32)) {
this._lastReference, return 'Invalid publicKey'
this._keyPair.publicKey }
] if (!(this._keyPair.privateKey instanceof Uint8Array && this._keyPair.privateKey.byteLength === 64)) {
} return 'Invalid privateKey'
}
get chatBytes() { return true
const isValid = this.validParams() }
if (!isValid.valid) { ]
throw new Error(isValid.message) }
}
set keyPair(keyPair) {
let result = new Uint8Array() this._keyPair = keyPair
}
this.params.forEach(item => {
result = this.constructor.utils.appendBuffer(result, item) set type(type) {
}) this.typeText = TX_TYPES[type]
this._type = type
this._chatBytes = result this._typeBytes = this.constructor.utils.int32ToBytes(this._type)
}
return this._chatBytes
} set groupID(groupID) {
this._groupID = groupID
validParams() { this._groupIDBytes = this.constructor.utils.int32ToBytes(this._groupID)
let finalResult = { }
valid: true
} set timestamp(timestamp) {
this._timestamp = timestamp
this.tests.some(test => { this._timestampBytes = this.constructor.utils.int64ToBytes(this._timestamp)
const result = test() }
if (result !== true) {
finalResult = { set fee(fee) {
valid: false, this._fee = fee * QORT_DECIMALS
message: result this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
} }
return true
} set lastReference(lastReference) {
}) this._lastReference = lastReference instanceof Uint8Array ? lastReference : this.constructor.Base58.decode(lastReference)
return finalResult }
}
get params() {
return [
this._typeBytes,
this._timestampBytes,
this._groupIDBytes,
this._lastReference,
this._keyPair.publicKey
]
}
get chatBytes() {
const isValid = this.validParams()
if (!isValid.valid) {
throw new Error(isValid.message)
}
let result = new Uint8Array()
this.params.forEach(item => {
result = this.constructor.utils.appendBuffer(result, item)
})
this._chatBytes = result
return this._chatBytes
}
validParams() {
let finalResult = {
valid: true
}
this.tests.some(test => {
const result = test()
if (result !== true) {
finalResult = {
valid: false,
message: result
}
return true
}
})
return finalResult
}
} }

2
qortal-ui-crypto/api/transactions/chat/ChatTransaction.js

@ -67,7 +67,7 @@ export default class ChatTransaction extends ChatBase {
} }
get params() { get params() {
const params = super.params; const params = super.params
params.push( params.push(
this._proofOfWorkNonce, this._proofOfWorkNonce,
this._hasReceipient, this._hasReceipient,

3
qortal-ui-crypto/api/transactions/chat/GroupChatTransaction.js

@ -1,5 +1,6 @@
'use strict' 'use strict'
import ChatBase from "./ChatBase.js" import ChatBase from "./ChatBase.js"
import { CHAT_REFERENCE_FEATURE_TRIGGER_TIMESTAMP } from '../../constants.js'
export default class GroupChatTransaction extends ChatBase { export default class GroupChatTransaction extends ChatBase {
constructor() { constructor() {
@ -43,7 +44,7 @@ export default class GroupChatTransaction extends ChatBase {
} }
get params() { get params() {
const params = super.params; const params = super.params
params.push( params.push(
this._proofOfWorkNonce, this._proofOfWorkNonce,
this._hasReceipient, this._hasReceipient,

Loading…
Cancel
Save