Skip to content

Commit

Permalink
Port latest changes from go-nitro till commit 9afe205 on August 16 (#…
Browse files Browse the repository at this point in the history
…114)

* Update AllocationUpdatedEvent

* Add EventQueue and new block sub to wait for block confirmations

* Update contract-bindings using latest @statechannels/nitro-protocol

* Convert BigNumber to bigint for AllocationUpdatedEvent

* Hoist @cerc-io/nitro-protocol to workspace root

* Rename variable to GENERAL_MSG_PROTOCOL_ID

* Set Hardhat interval mining mode to 1s

* Use @cerc-io/nitro-protocol version v2.0.0-alpha.4-ts-port-0.1.2

* Update yarn lock

* Handle review comments

* Update workflow to build watcher-ts in root

---------

Co-authored-by: neeraj <neeraj.rtly@gmail.com>
  • Loading branch information
nikugogoi and neerajvijay1997 authored Sep 7, 2023
1 parent 7ea01a5 commit aab43de
Show file tree
Hide file tree
Showing 18 changed files with 7,329 additions and 3,113 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ jobs:
path: ./watcher-ts
- name: "Run relay node"
run: |
cd ./watcher-ts/packages/peer
cd ./watcher-ts
yarn && yarn build
cd ./packages/peer
yarn create-peer -f relay-id.json
export RELAY_PEER_ID=$(jq -r '.id' relay-id.json)
echo "RELAY_MULTIADDR=/ip4/127.0.0.1/tcp/9090/ws/p2p/$RELAY_PEER_ID" >> "$GITHUB_ENV"
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
],
"nohoist": [
"**/mocha",
"**/mocha/**",
"**/@cerc-io/nitro-protocol"
"**/mocha/**"
]
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions packages/nitro-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@typechain/ethers-v5": "^11.0.0",
"@types/chai": "^4.3.5",
"@types/debug": "^4.1.7",
"@types/heap": "^0.2.31",
"@types/lodash": "^4.14.195",
"@types/mocha": "^10.0.1",
"@types/node": "^20.2.1",
Expand Down Expand Up @@ -60,6 +61,7 @@
"assert": "^2.0.0",
"debug": "^4.3.4",
"ethers": "^5.7.2",
"heap": "^0.2.7",
"it-pipe": "^2.0.5",
"level": "^8.0.0",
"lodash": "^4.17.21",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,15 @@
/* eslint-disable @typescript-eslint/no-use-before-define */

import { Transaction, utils, providers } from 'ethers';
import {
Transaction, utils, providers,
} from 'ethers';

import { AllocationUpdatedEventObject, INitroTypes, NitroAdjudicator } from './adjudicator/nitro-adjudicator';
import { Address } from '../../../types/types';
import { Destination } from '../../../types/destination';

// getAssetHoldings reads on-chain holdings for a channel,asset address, and block number
async function getAssetHoldings(
na: NitroAdjudicator,
assetAddress: Address,
blockNumber: bigint | undefined,
channelId: Destination,
): Promise<bigint> {
const amount = await na.holdings(assetAddress, channelId.value, { blockTag: Number(blockNumber) });
return amount.toBigInt();
}

// getChainHolding reads on-chain holdings for a channel and an asset address given a transaction and an event generated by the transaction.
export async function getChainHolding(
na: NitroAdjudicator,
tx: providers.TransactionResponse,
event: AllocationUpdatedEventObject,
): Promise<[string, bigint]> {
// Use providers.TransactionResponse as the type for tx to access blockNumber
// (block number not part of the event unlike in go-nitro)
const blockNumber = tx.blockNumber!;

const assetAddress = assetAddressForIndex(na, tx, event.assetIndex.toBigInt());
const amount = await getAssetHoldings(na, assetAddress, BigInt(blockNumber), new Destination(event.channelId));

return [assetAddress, amount];
}

// assetAddressForIndex uses the input parameters of a transaction to map an asset index to an asset address
function assetAddressForIndex(na: NitroAdjudicator, tx: Transaction, index?: bigint): Address {
export function assetAddressForIndex(na: NitroAdjudicator, tx: Transaction, index?: bigint): Address {
const abiInterface = na.interface;
const params = decodeTxParams(abiInterface, tx);

Expand Down
Loading

0 comments on commit aab43de

Please sign in to comment.