Skip to content

Commit

Permalink
Add delayed messages to the api
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Jul 31, 2022
1 parent db229aa commit ec488d3
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
97 changes: 97 additions & 0 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
Permission,
FunctionCall,
TokensObject,
DelayedMessage,
} from './models';

import { UniqueArray, Address } from './utils';
Expand Down Expand Up @@ -64,6 +65,24 @@ export type ProviderEvents<Addr = Address> = {
state: ContractState;
};

/**
* Called every time a delayed message was delivered or expired
*/
messageStatusUpdated: {
/**
* Account address
*/
address: Addr,
/**
* Message hash
*/
hash: string;
/**
* If not null, the transaction of the delivered message. Otherwise, the message has expired.
*/
transaction?: Transaction<Addr>;
}

/**
* Called each time the user changes network
*/
Expand Down Expand Up @@ -1154,6 +1173,47 @@ export type ProviderApi<Addr = Address> = {
};
};

/**
* Sends an internal message from the user account without waiting for the transaction.
* Shows an approval window to the user.
*
* @see messageStatusUpdated
*
* ---
* Required permissions: `accountInteraction`
*/
sendMessageDelayed: {
input: {
/**
* Preferred wallet address.
* It is the same address as the `accountInteraction.address`, but it must be explicitly provided
*/
sender: Addr;
/**
* Message destination address
*/
recipient: Addr;
/**
* Amount of nano EVER to send
*/
amount: string;
/**
* Whether to bounce message back on error
*/
bounce: boolean;
/**
* Optional function call
*/
payload?: FunctionCall<Addr>;
};
output: {
/**
* External message info
*/
message: DelayedMessage<Addr>;
};
};

/**
* Sends an external message to the contract
* Shows and approval window to the user
Expand Down Expand Up @@ -1197,6 +1257,43 @@ export type ProviderApi<Addr = Address> = {
output: TokensObject<Addr> | undefined;
};
};

/**
* Sends an external message to the contract without waiting for the transaction.
* Shows and approval window to the user
*
* @see messageStatusUpdated
*
* ---
* Required permissions: `accountInteraction`
*/
sendExternalMessageDelayed: {
input: {
/**
* The public key of the preferred account.
* It is the same publicKey as the `accountInteraction.publicKey`, but it must be explicitly provided
*/
publicKey: string;
/**
* Message destination address
*/
recipient: Addr;
/**
* Optional base64 encoded `.tvc` file
*/
stateInit?: string;
/**
* Function call
*/
payload: FunctionCall<Addr>;
};
output: {
/**
* External message info
*/
message: DelayedMessage<Addr>;
};
};
};

/**
Expand Down
18 changes: 18 additions & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,24 @@ export function parseMessage(message: RawMessage): Message {
};
}

/**
* @category Models
*/
export type DelayedMessage<Addr = Address> = {
/**
* External message hash
*/
hash: string;
/**
* Destination account address (`sender` for `sendMessageDelayed`, `recipient` for `sendExternalMessageDelayed`)
*/
account: Addr,
/**
* Message expiration timestamp
*/
expireAt: number;
}

/**
* @category Models
*/
Expand Down

0 comments on commit ec488d3

Please sign in to comment.