createWrappedResponse
createWrappedResponse
is a function that needs to be called in order to return a wrappedResponse
in the getRelevantData function of setup.
This function needs 5 parameters passed into it:
accountId
- the account ID that's passed intogetRelevantData
accountCreated
- a boolean indicating whether or not an account was created for the first timeaccountHash
- the hash field on the accountaccountTimestamp
- the timestamp field on the accountaccount
- the entire account object
💡
The example shown below demonstrates how to use this function within a chat application.
getRelevantData(accountId, tx) {
let account = accounts[accountId]
let accountCreated = false
// Create the account if it doesn't exist
if (typeof account === 'undefined' || account === null) {
if (tx.type === 'register') {
if (accountId === tx.aliasHash) {
account = createAlias(accountId)
accounts[accountId] = account
accountCreated = true
}
} else if (tx.type === 'message') {
if (accountId === tx.chatId) {
account = createChat(accountId)
accounts[accountId] = account
accountCreated = true
}
}
}
if (typeof account === 'undefined' || account === null) {
account = createAccount(accountId, tx.timestamp)
accounts[accountId] = account
accountCreated = true
}
// Wrap it for Shardus
const wrapped = dapp.createWrappedResponse(accountId, accountCreated, account.hash, account.timestamp, account)
return wrapped
}