Skip to content

Commit

Permalink
feat: 🎸 Add value parameter to ContractMessage
Browse files Browse the repository at this point in the history
✅ Closes: #7
  • Loading branch information
lovel8 committed Jan 18, 2024
1 parent 9cf02f0 commit 93083b7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
27 changes: 27 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"workbench.editor.enablePreview": false,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"standard.autoFixOnSave": true,
"standard.nodePath": "",
"eslint.options": {},
"previewServer.ui": {},
"prettier.semi": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"eslint.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"prettier.tabWidth": 4,
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"window.zoomLevel": 1,
"workbench.colorTheme": "Solidity Visual Developer Dark",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.updateImportsOnFileMove.enabled": "never"
}
1 change: 1 addition & 0 deletions src/contractMessage/decoder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class ContractMessageDecoder {
timestamp: "", // Add timestamp logic here if available
from: msg.Msg.From,
to: msg.Msg.To,
value: msg.Msg.Value,
method: decodeInputRes.data.method,
params: decodeInputRes.data.params,
status: msg.MsgRct ? msg.MsgRct.ExitCode : "",
Expand Down
28 changes: 26 additions & 2 deletions src/contractMessage/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
********************************************************************************/

import { CidProperty } from "../../basic/cid/types"
import { Entity } from "@unipackage/ddd"
import { ValueFields } from "@unipackage/utils"

/**
* Interface representing a ContractMessage.
Expand All @@ -35,6 +35,8 @@ export interface ContractMessage {
from: string
/** Recipient's address to which the contract message is directed. */
to: string
/** The amount sent by the contract message. */
value: string
/** Method associated with the contract message. */
method: string
/** Parameters of the contract message. */
Expand All @@ -48,4 +50,26 @@ export interface ContractMessage {
/**
* class representing a ContractMessage.
*/
export class ContractMessage extends Entity<ContractMessage> {}
export class ContractMessage {
/**
* Creates an instance of the ContractMessage.
* @param data - The initial data for the ContractMessage.
*/
constructor(data: ValueFields<ContractMessage>) {
if (!data) {
throw new Error("Invalid data provided to the constructor")
}
Object.assign(this, data)
}

/**
* Gets the values of the ContractMessage.
* @returns ValueFields<ContractMessage>.
*/
values(): ValueFields<ContractMessage> {
return Object.fromEntries(
Object.entries(this)
.filter(([key, value]) => this.hasOwnProperty(key) && typeof value !== "function")
) as ValueFields<ContractMessage>;
}
}
1 change: 1 addition & 0 deletions test/contractMessage/contractMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("ContractMessage Entity", () => {
timestamp: "2023-01-01T12:00:00Z",
from: "senderAddress",
to: "recipientAddress",
value: "1000000000",
method: "transfer",
params: {
/* Add parameter properties */
Expand Down
1 change: 1 addition & 0 deletions test/contractMessage/decoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ describe("ContractMessageDecoder", () => {
timestamp: "",
from: "f410fhuebctou6znv3xghmceeesoz2gxegxpoopw46jq",
to: "f410few7qcnlenzfodimzo72ki7kmh5zlg6munfg5l4q",
value: "1000000000",
method: "appendDatasetCollateral",
params: {
datasetId: BigInt(1),
Expand Down

0 comments on commit 93083b7

Please sign in to comment.