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

Update circles-core dependency and use new pathfinder service #630

Merged
merged 14 commits into from
Apr 24, 2023
Merged
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ ETHEREUM_NODE_WS=ws://localhost:8545
# Service Endpoints
API_SERVICE_EXTERNAL=http://api.circles.local
GRAPH_NODE_EXTERNAL=http://graph.circles.local
PATHFINDER_SERVICE_ENDPOINT=http://localhost:8081
RELAY_SERVICE_EXTERNAL=http://relay.circles.local

# Database Endpoints
DATABASE_SOURCE=graph

# Pathfinder Type 'cli' or 'server'.
# The core library can get the transfer steps from a pathfinder service ('server'), or from the circles-api that uses the cli tool ('cli')
PATHFINDER_TYPE=server

# Smart Contract addresses of 1.3.0 version
HUB_ADDRESS=0xCfEB869F69431e42cdB54A4F4f105C19C080A601
PROXY_FACTORY_ADDRESS=0x9b1f7F645351AF3631a656421eD2e40f2802E6c0
Expand Down
2 changes: 1 addition & 1 deletion locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
"errorMessage": "Something went wrong .. {errorMessage}",
"errorMessageCannotBeCalculated": "Maximum amount cannot be calculated at this time.",
"errorMessageTransferInvalid": "Could not transfer Circles as it is invalid.",
"errorMessageTransferNotFound": "Could not transfer Circles as there is currently no complete trust path between @{username} and you ..",
"errorMessageTransferNotFound": "The transaction to @{username} could not be completed due to the trust paths. Try smaller amounts.",
"errorMessageTransferTooComplex": "Could not transfer Circles as there are too many hops required to send Circles to @{username}. Consider sending a smaller amount and ask @{username} to trust you directly to make this transfer easier.",
"errorMessageTransferUnknown": "Could not transfer Circles. Something went wrong!",
"formAmount": "Enter amount",
Expand Down
78 changes: 77 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/components/ButtonWobbly.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const ButtonWobbly = ({
isReady,
isPending,
onClick,
to,
}) => {
const classes = useStyles();
const IconElement = iconSelector(icon);
Expand Down
55 changes: 33 additions & 22 deletions src/store/token/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,30 +315,41 @@ export function transfer(
const value = new web3.utils.BN(
core.utils.toFreckles(tcToCrc(Date.now(), Number(amount))),
);
const txHash = await loopTransfer(
from,
to,
value,
paymentNote,
hops,
attempts,
);
let txHash;

dispatch(
addPendingActivity({
txHash,
type: ActivityTypes.HUB_TRANSFER,
data: {
from,
to,
value: value.toString(),
},
}),
);
if (process.env.PATHFINDER_TYPE === 'cli') {
txHash = await loopTransfer(
from,
to,
value,
paymentNote,
hops,
attempts,
);
} else {
txHash = await core.token.transfer(from, to, value, paymentNote);
}

dispatch({
type: ActionTypes.TOKEN_TRANSFER_SUCCESS,
});
if (txHash !== null) {
dispatch(
addPendingActivity({
txHash,
type: ActivityTypes.HUB_TRANSFER,
data: {
from,
to,
value: value.toString(),
},
}),
);

dispatch({
type: ActionTypes.TOKEN_TRANSFER_SUCCESS,
});
} else {
// "TransactionServiceException: execution reverted" as an example coming from core.token.transfer
throw new TransferError();
}
} catch (error) {
dispatch({
type: ActionTypes.TOKEN_TRANSFER_ERROR,
Expand Down
28 changes: 20 additions & 8 deletions src/utils/findPath.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const LARGE_AMOUNT = new web3.utils.BN(
web3.utils.toWei('1000000000000000', 'ether'),
);

// Recursive helper function for findMaxFlow
// Recursive helper function for findMaxFlow recursively reducing number of hops
async function loopFindMaxFlow(
from,
to,
Expand Down Expand Up @@ -60,14 +60,26 @@ async function loopFindMaxFlow(
* @returns nothing. Updates MaxFlow state in Freckles.
*/
export async function findMaxFlow(from, to, setMaxFlow) {
// First attempting via API
// First attempting via API.
// The API parameters depends on the Pathfinder Type in use:
// The 'cli' uses hops, but this option is not available in the 'server'.
// Therefore we set the attemptsLeft and the hops option will be ignored.
try {
const response = await loopFindMaxFlow(
from,
to,
PATHFINDER_HOPS_DEFAULT,
PATHFINDER_HOPS_DEFAULT,
);
let response;
if (process.env.PATHFINDER_TYPE === 'cli') {
response = await loopFindMaxFlow(
from,
to,
PATHFINDER_HOPS_DEFAULT,
PATHFINDER_HOPS_DEFAULT,
);
} else {
response = await core.token.findTransitiveTransfer(
from,
to,
LARGE_AMOUNT,
);
}

// Throw an error when no path was found, we should try again with
// checking direct sends as the API might not be in sync yet
Expand Down
2 changes: 2 additions & 0 deletions src/views/SendConfirm.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ const SendConfirm = () => {
messageId = 'Invalid';
} else if (error.code === ErrorCodes.TRANSFER_NOT_FOUND) {
messageId = 'NotFound';
} else if (error.code === ErrorCodes.UNKNOWN_ERROR) {
messageId = 'Unknown';
}
text = translate('SendConfirm.errorMessageTransfer' + messageId, {
amount,
Expand Down