Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@omisego/omg-js-rootchain

Package Overview
Dependencies
Maintainers
5
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@omisego/omg-js-rootchain - npm Package Compare versions

Comparing version 0.1.5 to 0.1.7

LICENSE

6

package.json
{
"name": "@omisego/omg-js-rootchain",
"version": "0.1.5",
"version": "0.1.7",
"description": "Module to interact with the Ethereum RootChain",

@@ -25,3 +25,3 @@ "keywords": [

"dependencies": {
"@omisego/omg-js-util": "^0.1.5",
"@omisego/omg-js-util": "^0.1.7",
"debug": "^4.0.1",

@@ -34,3 +34,3 @@ "web3-eth": "^1.0.0-beta.36",

},
"gitHead": "b8453a9d064390e61e4f187d24675046232d69d7"
"gitHead": "96445b5c2197d63dabf93da9484934c26d8fd689"
}

@@ -0,2 +1,16 @@

/*
Copyright 2018 OmiseGO Pte 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. */
const Web3Eth = require('web3-eth')

@@ -8,3 +22,2 @@ const Web3Utils = require('web3-utils')

class RootChain {
/**

@@ -18,5 +31,8 @@ * Interact with Tesuji Plasma Rootchain from JavaScript (Node.js and Browser)

constructor (web3Provider) {
constructor (web3Provider, plasmaContractAddress) {
this.eth = new Web3Eth(web3Provider)
this.plasmaContractAddress = plasmaContractAddress
this.plasmaContract = new this.eth.Contract(plasmaAbi.abi, plasmaContractAddress)
}
/**

@@ -31,15 +47,16 @@ * deposit ETH to rootchain

*/
async depositEth (amount, fromAddress, plasmaContractAddress) {
const receipt = await this.eth.sendTransaction({
async depositEth (amount, fromAddress, privateKey) {
const txDetails = {
from: fromAddress,
to: plasmaContractAddress,
value: Web3Utils.toWei(amount.toString(), 'ether'),
data: '0xd0e30db0' // TODO What's this data for?
})
debug(`deposit receipt: ${receipt}`)
debug(`returned transaction hash: ${receipt.transactionHash}`)
return receipt.transactionHash
to: this.plasmaContractAddress,
value: amount,
data: this.plasmaContract.methods.deposit().encodeABI(),
gas: 2000000
}
return sendTx(this.eth, txDetails, privateKey)
}
/**
/**
* deposit Token to rootchain

@@ -55,14 +72,11 @@ *

async depositToken (amount, plasmaContractAddress, fromAddress, tokenAddress) {
const plasmaContract = new this.eth.Contract(plasmaAbi.abi, plasmaContractAddress)
const depositData = plasmaContract.methods.depositFrom(fromAddress, tokenAddress, amount).encodeABI()
const receipt = await this.eth.sendTransaction({
async depositToken (amount, fromAddress, tokenAddress, privateKey) {
const txDetails = {
from: fromAddress,
to: plasmaContractAddress,
data: depositData
})
to: this.plasmaContractAddress,
data: this.plasmaContract.methods.depositFrom(fromAddress, tokenAddress, amount).encodeABI(),
gas: 2000000
}
debug(`depositToken receipt: ${receipt}`)
debug(`depositToken transaction hash: ${receipt.transactionHash}`)
return receipt.transactionHash
return sendTx(this.eth, txDetails, privateKey)
}

@@ -88,4 +102,43 @@

}
async startExit (fromAddress, utxoPos, txBytes, proof, sigs, privateKey) {
const txDetails = {
from: fromAddress,
to: this.plasmaContractAddress,
data: this.plasmaContract.methods.startExit(
utxoPos,
Web3Utils.hexToBytes(`0x${txBytes}`),
Web3Utils.hexToBytes(`0x${proof}`),
Web3Utils.hexToBytes(`0x${sigs}`)
).encodeABI(),
gas: 2000000
}
return sendTx(this.eth, txDetails, privateKey)
}
async finalizeExits (fromAddress, token, privateKey) {
const txDetails = {
from: fromAddress,
to: this.plasmaContractAddress,
data: this.plasmaContract.methods.finalizeExits(token).encodeABI(),
gas: 2000000
}
return sendTx(this.eth, txDetails, privateKey)
}
}
async function sendTx (eth, txDetails, privateKey) {
if (!privateKey) {
// No privateKey to sign with, assume sending from an unlocked geth account
return eth.sendTransaction(txDetails)
} else {
// First sign the transaction
const signedTx = await eth.accounts.signTransaction(txDetails, privateKey)
// Then send it
return eth.sendSignedTransaction(signedTx.rawTransaction)
}
}
module.exports = RootChain

@@ -0,1 +1,16 @@

/*
Copyright 2018 OmiseGO Pte 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. */
// this is ABI for Plasma contract

@@ -2,0 +17,0 @@

@@ -0,1 +1,16 @@

/*
Copyright 2018 OmiseGO Pte 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. */
// testing ETH function

@@ -2,0 +17,0 @@ const mocha = require('mocha')

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc