mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-04-23 19:37:52 +00:00
added qortalRequests register name, update name
This commit is contained in:
parent
2e959116fd
commit
42424c08b8
@ -2076,7 +2076,7 @@ export async function cancelBan({ groupId, qortalAddress }) {
|
|||||||
throw new Error("Transaction was not able to be processed");
|
throw new Error("Transaction was not able to be processed");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
export async function registerName({ name }) {
|
export async function registerName({ name, description = "" }) {
|
||||||
const lastReference = await getLastRef();
|
const lastReference = await getLastRef();
|
||||||
const resKeyPair = await getKeyPair();
|
const resKeyPair = await getKeyPair();
|
||||||
const parsedData = resKeyPair;
|
const parsedData = resKeyPair;
|
||||||
@ -2091,7 +2091,34 @@ export async function registerName({ name }) {
|
|||||||
const tx = await createTransaction(3, keyPair, {
|
const tx = await createTransaction(3, keyPair, {
|
||||||
fee: feeres.fee,
|
fee: feeres.fee,
|
||||||
name,
|
name,
|
||||||
value: "",
|
value: description || "",
|
||||||
|
lastReference: lastReference,
|
||||||
|
});
|
||||||
|
|
||||||
|
const signedBytes = Base58.encode(tx.signedBytes);
|
||||||
|
|
||||||
|
const res = await processTransactionVersion2(signedBytes);
|
||||||
|
if (!res?.signature)
|
||||||
|
throw new Error(res?.message || "Transaction was not able to be processed");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
export async function updateName({ newName, oldName, description }) {
|
||||||
|
const lastReference = await getLastRef();
|
||||||
|
const resKeyPair = await getKeyPair();
|
||||||
|
const parsedData = resKeyPair;
|
||||||
|
const uint8PrivateKey = Base58.decode(parsedData.privateKey);
|
||||||
|
const uint8PublicKey = Base58.decode(parsedData.publicKey);
|
||||||
|
const keyPair = {
|
||||||
|
privateKey: uint8PrivateKey,
|
||||||
|
publicKey: uint8PublicKey,
|
||||||
|
};
|
||||||
|
const feeres = await getFee("UPDATE_NAME");
|
||||||
|
|
||||||
|
const tx = await createTransaction(4, keyPair, {
|
||||||
|
fee: feeres.fee,
|
||||||
|
name: oldName,
|
||||||
|
newName,
|
||||||
|
newData: description || "",
|
||||||
lastReference: lastReference,
|
lastReference: lastReference,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ export const UIQortalRequests = [
|
|||||||
'GET_WALLET_BALANCE', 'GET_USER_WALLET_INFO', 'GET_CROSSCHAIN_SERVER_INFO',
|
'GET_WALLET_BALANCE', 'GET_USER_WALLET_INFO', 'GET_CROSSCHAIN_SERVER_INFO',
|
||||||
'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE',
|
'GET_TX_ACTIVITY_SUMMARY', 'GET_FOREIGN_FEE', 'UPDATE_FOREIGN_FEE',
|
||||||
'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER',
|
'GET_SERVER_CONNECTION_HISTORY', 'SET_CURRENT_FOREIGN_SERVER',
|
||||||
'ADD_FOREIGN_SERVER', 'REMOVE_FOREIGN_SERVER', 'GET_DAY_SUMMARY', 'CREATE_TRADE_BUY_ORDER', 'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION', 'SIGN_TRANSACTION', 'OPEN_NEW_TAB', 'CREATE_AND_COPY_EMBED_LINK', 'DECRYPT_QORTAL_GROUP_DATA', 'DECRYPT_DATA_WITH_SHARING_KEY', 'DELETE_HOSTED_DATA', 'GET_HOSTED_DATA', 'SHOW_ACTIONS'
|
'ADD_FOREIGN_SERVER', 'REMOVE_FOREIGN_SERVER', 'GET_DAY_SUMMARY', 'CREATE_TRADE_BUY_ORDER', 'CREATE_TRADE_SELL_ORDER', 'CANCEL_TRADE_SELL_ORDER', 'IS_USING_GATEWAY', 'ADMIN_ACTION', 'SIGN_TRANSACTION', 'OPEN_NEW_TAB', 'CREATE_AND_COPY_EMBED_LINK', 'DECRYPT_QORTAL_GROUP_DATA', 'DECRYPT_DATA_WITH_SHARING_KEY', 'DELETE_HOSTED_DATA', 'GET_HOSTED_DATA', 'SHOW_ACTIONS', 'REGISTER_NAME', 'UPDATE_NAME'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { gateways, getApiKeyFromStorage } from "./background";
|
import { gateways, getApiKeyFromStorage } from "./background";
|
||||||
import { listOfAllQortalRequests } from "./components/Apps/useQortalMessageListener";
|
import { listOfAllQortalRequests } from "./components/Apps/useQortalMessageListener";
|
||||||
import { addForeignServer, addListItems, adminAction, cancelSellOrder, createAndCopyEmbedLink, createBuyOrder, createPoll, createSellOrder, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, openNewTab, publishMultipleQDNResources, publishQDNResource, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, voteOnPoll } from "./qortalRequests/get";
|
import { addForeignServer, addListItems, adminAction, cancelSellOrder, createAndCopyEmbedLink, createBuyOrder, createPoll, createSellOrder, decryptData, decryptDataWithSharingKey, decryptQortalGroupData, deleteHostedData, deleteListItems, deployAt, encryptData, encryptDataWithSharingKey, encryptQortalGroupData, getCrossChainServerInfo, getDaySummary, getForeignFee, getHostedData, getListItems, getServerConnectionHistory, getTxActivitySummary, getUserAccount, getUserWallet, getUserWalletInfo, getWalletBalance, joinGroup, openNewTab, publishMultipleQDNResources, publishQDNResource, registerNameRequest, removeForeignServer, saveFile, sendChatMessage, sendCoin, setCurrentForeignServer, signTransaction, updateForeignFee, updateNameRequest, voteOnPoll } from "./qortalRequests/get";
|
||||||
import { getData, storeData } from "./utils/chromeStorage";
|
import { getData, storeData } from "./utils/chromeStorage";
|
||||||
|
|
||||||
|
|
||||||
@ -886,6 +886,44 @@ export const isRunningGateway = async ()=> {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "REGISTER_NAME" : {
|
||||||
|
try {
|
||||||
|
const res = await registerNameRequest(request.payload, isFromExtension)
|
||||||
|
event.source.postMessage({
|
||||||
|
requestId: request.requestId,
|
||||||
|
action: request.action,
|
||||||
|
payload: res,
|
||||||
|
type: "backgroundMessageResponse",
|
||||||
|
}, event.origin);
|
||||||
|
} catch (error) {
|
||||||
|
event.source.postMessage({
|
||||||
|
requestId: request.requestId,
|
||||||
|
action: request.action,
|
||||||
|
error: error?.message,
|
||||||
|
type: "backgroundMessageResponse",
|
||||||
|
}, event.origin);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "UPDATE_NAME" : {
|
||||||
|
try {
|
||||||
|
const res = await updateNameRequest(request.payload, isFromExtension)
|
||||||
|
event.source.postMessage({
|
||||||
|
requestId: request.requestId,
|
||||||
|
action: request.action,
|
||||||
|
payload: res,
|
||||||
|
type: "backgroundMessageResponse",
|
||||||
|
}, event.origin);
|
||||||
|
} catch (error) {
|
||||||
|
event.source.postMessage({
|
||||||
|
requestId: request.requestId,
|
||||||
|
action: request.action,
|
||||||
|
error: error?.message,
|
||||||
|
type: "backgroundMessageResponse",
|
||||||
|
}, event.origin);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ import {
|
|||||||
performPowTask,
|
performPowTask,
|
||||||
parseErrorResponse,
|
parseErrorResponse,
|
||||||
groupSecretkeys,
|
groupSecretkeys,
|
||||||
|
registerName,
|
||||||
|
updateName,
|
||||||
} from "../background";
|
} from "../background";
|
||||||
import { getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption";
|
import { getNameInfo, uint8ArrayToObject } from "../backgroundFunctions/encryption";
|
||||||
import { showSaveFilePicker } from "../components/Apps/useQortalMessageListener";
|
import { showSaveFilePicker } from "../components/Apps/useQortalMessageListener";
|
||||||
@ -3851,4 +3853,61 @@ export const createAndCopyEmbedLink = async (data, isFromExtension) => {
|
|||||||
throw new Error('Invalid type')
|
throw new Error('Invalid type')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
export const registerNameRequest = async (data, isFromExtension) => {
|
||||||
|
const requiredFields = ["name"];
|
||||||
|
const missingFields: string[] = [];
|
||||||
|
requiredFields.forEach((field) => {
|
||||||
|
if (!data[field]) {
|
||||||
|
missingFields.push(field);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const resPermission = await getUserPermission(
|
||||||
|
{
|
||||||
|
text1: `Do you give this application permission to register this name?`,
|
||||||
|
highlightedText: data.name,
|
||||||
|
text2: data?.description
|
||||||
|
},
|
||||||
|
isFromExtension
|
||||||
|
);
|
||||||
|
const { accepted } = resPermission;
|
||||||
|
if (accepted) {
|
||||||
|
const name = data.name
|
||||||
|
const description = data?.description
|
||||||
|
const response = await registerName({ name, description });
|
||||||
|
return response
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error("User declined request");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const updateNameRequest = async (data, isFromExtension) => {
|
||||||
|
const requiredFields = ["newName", "oldName"];
|
||||||
|
const missingFields: string[] = [];
|
||||||
|
requiredFields.forEach((field) => {
|
||||||
|
if (!data[field]) {
|
||||||
|
missingFields.push(field);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const oldName = data.oldName
|
||||||
|
const newName = data.newName
|
||||||
|
const description = data?.description
|
||||||
|
const resPermission = await getUserPermission(
|
||||||
|
{
|
||||||
|
text1: `Do you give this application permission to register this name?`,
|
||||||
|
highlightedText: data.newName,
|
||||||
|
text2: data?.description
|
||||||
|
},
|
||||||
|
isFromExtension
|
||||||
|
);
|
||||||
|
const { accepted } = resPermission;
|
||||||
|
if (accepted) {
|
||||||
|
const response = await updateName({ oldName, newName, description });
|
||||||
|
return response
|
||||||
|
|
||||||
|
} else {
|
||||||
|
throw new Error("User declined request");
|
||||||
|
}
|
||||||
};
|
};
|
51
src/transactions/UpdateNameTransaction.ts
Normal file
51
src/transactions/UpdateNameTransaction.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
|
||||||
|
import { QORT_DECIMALS } from "../constants/constants"
|
||||||
|
import TransactionBase from "./TransactionBase"
|
||||||
|
|
||||||
|
|
||||||
|
export default class UpdateNameTransaction extends TransactionBase {
|
||||||
|
constructor() {
|
||||||
|
super()
|
||||||
|
this.type = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
set fee(fee) {
|
||||||
|
this._fee = fee * QORT_DECIMALS
|
||||||
|
this._feeBytes = this.constructor.utils.int64ToBytes(this._fee)
|
||||||
|
}
|
||||||
|
|
||||||
|
set name(name) {
|
||||||
|
this.nameText = name
|
||||||
|
this._nameBytes = this.constructor.utils.stringtoUTF8Array(name)
|
||||||
|
this._nameLength = this.constructor.utils.int32ToBytes(this._nameBytes.length)
|
||||||
|
}
|
||||||
|
|
||||||
|
set newName(newName) {
|
||||||
|
this.newNameText = newName
|
||||||
|
this._newNameBytes = this.constructor.utils.stringtoUTF8Array(newName)
|
||||||
|
this._newNameLength = this.constructor.utils.int32ToBytes(this._newNameBytes.length)
|
||||||
|
}
|
||||||
|
|
||||||
|
set newData(newData) {
|
||||||
|
this.newDataText = newData.length === 0 ? "Registered Name on the Qortal Chain" : newData
|
||||||
|
this._newDataBytes = this.constructor.utils.stringtoUTF8Array(this.newDataText)
|
||||||
|
this._newDataLength = this.constructor.utils.int32ToBytes(this._newDataBytes.length)
|
||||||
|
}
|
||||||
|
|
||||||
|
get params() {
|
||||||
|
const params = super.params
|
||||||
|
params.push(
|
||||||
|
this._nameLength,
|
||||||
|
this._nameBytes,
|
||||||
|
this._newNameLength,
|
||||||
|
this._newNameBytes,
|
||||||
|
this._newDataLength,
|
||||||
|
this._newDataBytes,
|
||||||
|
this._feeBytes
|
||||||
|
)
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
}
|
@ -19,10 +19,12 @@ import CreatePollTransaction from './CreatePollTransaction.js'
|
|||||||
import DeployAtTransaction from './DeployAtTransaction.js'
|
import DeployAtTransaction from './DeployAtTransaction.js'
|
||||||
import RewardShareTransaction from './RewardShareTransaction.js'
|
import RewardShareTransaction from './RewardShareTransaction.js'
|
||||||
import RemoveRewardShareTransaction from './RemoveRewardShareTransaction.js'
|
import RemoveRewardShareTransaction from './RemoveRewardShareTransaction.js'
|
||||||
|
import UpdateNameTransaction from './UpdateNameTransaction.js'
|
||||||
|
|
||||||
|
|
||||||
export const transactionTypes = {
|
export const transactionTypes = {
|
||||||
3: RegisterNameTransaction,
|
3: RegisterNameTransaction,
|
||||||
|
4: UpdateNameTransaction,
|
||||||
2: PaymentTransaction,
|
2: PaymentTransaction,
|
||||||
8: CreatePollTransaction,
|
8: CreatePollTransaction,
|
||||||
9: VoteOnPollTransaction,
|
9: VoteOnPollTransaction,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user