Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to get active message hash for a given account address. #601

Merged
merged 9 commits into from
Jan 21, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 57 additions & 6 deletions contracts/gateway/GatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -338,20 +338,71 @@ contract GatewayBase is Organized {
emit BountyChangeConfirmed(previousBountyAmount_, changedBountyAmount_);
}

/**
* @notice Method to get the active message hash and its status from inbox
* for the given account address.
*
* @dev If message hash do not exists for the given account address then
deepesh-kn marked this conversation as resolved.
Show resolved Hide resolved
* it will return zero hash and undeclared status.
*
* @param _account Account address.
*
* @return messageHash_ Message hash.
* @return status_ Message status.
*/
function getInboxActiveProcess(
address _account
)
external
view
returns (
bytes32 messageHash_,
MessageBus.MessageStatus status_
)
{
messageHash_ = inboxActiveProcess[_account];
status_ = messageBox.inbox[messageHash_];
}

/**
* @notice Method to get the active message hash and its status from outbox
* for the given account address.
*
* @dev If message hash do not exists for the given account address then
deepesh-kn marked this conversation as resolved.
Show resolved Hide resolved
* it will return zero hash and undeclared status.
*
* @param _account Account address.
*
* @return messageHash_ Message hash.
* @return status_ Message status.
*/
function getOutboxActiveProcess(
address _account
)
external
view
returns (
bytes32 messageHash_,
MessageBus.MessageStatus status_
)
{
messageHash_ = outboxActiveProcess[_account];
status_ = messageBox.outbox[messageHash_];
}

/* Internal Functions */

/**
* @notice Calculate the fee amount which is rewarded to facilitator for
* performing message transfers.
*
* @param _gasConsumed gas consumption during message confirmation.
* @param _gasLimit maximum amount of gas can be used for reward.
* @param _gasPrice price at which reward is calculated
* @param _initialGas initial gas at the start of the process
* @param _gasConsumed Gas consumption during message confirmation.
* @param _gasLimit Maximum amount of gas can be used for reward.
* @param _gasPrice Price at which reward is calculated.
* @param _initialGas Initial gas at the start of the process.
*
* @return fee amount
* @return totalGasConsumed_ total gas consumed during message transfer
* @return fee_ Fee amount.
* @return totalGasConsumed_ Total gas consumed during message transfer.
*/
function feeAmount(
uint256 _gasConsumed,
Expand Down
175 changes: 175 additions & 0 deletions contracts/test/gateway/TestGatewayBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
pragma solidity ^0.5.0;

// Copyright 2019 OpenST Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ----------------------------------------------------------------------------
//
// http://www.simpletoken.org/
//
// ----------------------------------------------------------------------------

import "../../StateRootInterface.sol";
import "../../gateway/GatewayBase.sol";
import "../../lib/OrganizationInterface.sol";

/**
* @title TestGatewayBase contract.
*
* @notice Used for test only.
*/
contract TestGatewayBase is GatewayBase {

/* Constructor */

/**
* @notice This is used for testing.
*
* @param _stateRootProvider Contract address which implements
* StateRootInterface.
* @param _bounty The amount that facilitator will stakes to initiate the
* stake process.
* @param _organization Address of a contract that manages workers.
*/
constructor(
StateRootInterface _stateRootProvider,
uint256 _bounty,
OrganizationInterface _organization
)
public
GatewayBase(
_stateRootProvider,
_bounty,
_organization
)
{}

/* external functions */

/**
* @notice It is used to set a message.
*
* @dev This is used for testing purpose.
*
* @param _intentHash Intent hash.
* @param _nonce Nonce of the message sender address.
* @param _gasPrice Gas price that message sender is ready to pay to
* transfer message.
* @param _gasLimit Gas limit that message sender is ready to pay.
* @param _sender Message sender address.
* @param _hashLock Hash Lock provided by the facilitator.
*
* @return messageHash_ Hash unique for every request.
*/
function setMessage(
bytes32 _intentHash,
uint256 _nonce,
uint256 _gasPrice,
uint256 _gasLimit,
address _sender,
bytes32 _hashLock
)
external
returns (bytes32 messageHash_)
{
MessageBus.Message memory message = getMessage(
_intentHash,
_nonce,
_gasPrice,
_gasLimit,
_sender,
_hashLock
);

messageHash_ = MessageBus.messageDigest(
message.intentHash,
message.nonce,
message.gasPrice,
message.gasLimit,
message.sender,
message.hashLock
);

messages[messageHash_] = message;

}

/**
* @notice It sets the status of inbox.
*
* @dev This is used for testing purpose.
*
* @param _messageHash It sets the status of the message.
* @param _status It sets the state of the message.
*/
function setInboxStatus(
bytes32 _messageHash,
MessageBus.MessageStatus _status
)
external
{
messageBox.inbox[_messageHash] = _status;
}

/**
* @notice It sets the status of outbox.
*
* @dev This is used for testing purpose.
*
* @param _messageHash MessageHash for which status is the be set.
* @param _status Status of the message to be set.
*/
function setOutboxStatus(
bytes32 _messageHash,
MessageBus.MessageStatus _status
)
external
{
messageBox.outbox[_messageHash] = _status;
}

/**
* @notice It sets the message hash for active inbox process.
*
* @dev This is used for testing purpose.
*
* @param _account Account address.
* @param _messageHash MessageHash for which status is the be set.
*/
function setInboxProcess(
address _account,
bytes32 _messageHash
)
external
{
super.registerInboxProcess(_account, 1, _messageHash);
}

/**
* @notice It sets the message hash for active outbox process.
*
* @dev This is used for testing purpose.
*
* @param _account Account address.
* @param _messageHash MessageHash for which status is the be set.
*/
function setOutboxProcess(
address _account,
bytes32 _messageHash
)
external
{
super.registerOutboxProcess(_account, 1, _messageHash);
}
}
5 changes: 3 additions & 2 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const GatewayBase = artifacts.require("./gateway/GatewayBase.sol");
const EIP20Gateway = artifacts.require("EIP20Gateway");
const MockGatewayLib = artifacts.require("MockGatewayLib");
const MockGatewayBase = artifacts.require("MockGatewayBase");
const TestGatewayBase = artifacts.require("TestGatewayBase");
const MetaBlock = artifacts.require("../contracts/lib/MetaBlock.sol");
const BlockStore = artifacts.require("../contracts/BlockStore.sol");
const TestEIP20Gateway = artifacts.require("TestEIP20Gateway");
Expand Down Expand Up @@ -37,8 +38,8 @@ module.exports = function (deployer) {
deployer.deploy(GatewayLib);
deployer.deploy(MockGatewayLib);
deployer.deploy(MetaBlock);
deployer.link(GatewayLib, [GatewayBase, EIP20Gateway, TestEIP20Gateway, EIP20CoGateway, TestEIP20CoGateway]);
deployer.link(MessageBus, [EIP20CoGateway, TestEIP20CoGateway, TestEIP20Gateway, EIP20Gateway]);
deployer.link(GatewayLib, [GatewayBase, TestGatewayBase, EIP20Gateway, TestEIP20Gateway, EIP20CoGateway, TestEIP20CoGateway]);
deployer.link(MessageBus, [EIP20CoGateway, TestEIP20CoGateway, TestEIP20Gateway, EIP20Gateway, TestGatewayBase]);
deployer.link(MockGatewayLib, [MockGatewayBase, TestEIP20Gateway]);
deployer.link(MetaBlock, [BlockStore, AuxiliaryBlockStore]);

Expand Down
Loading