-
Notifications
You must be signed in to change notification settings - Fork 5
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 command to set the transfer proxy #16
Open
resonant-riches
wants to merge
2
commits into
lukebuehler:main
Choose a base branch
from
ChorusOne:set-transfer-proxy
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const ob = require('urbit-ob') | ||
const ajs = require('azimuth-js') | ||
const _ = require('lodash') | ||
const {files, validate, eth, azimuth, findPoints} = require('../../utils') | ||
|
||
exports.command = 'transfer-proxy' | ||
exports.desc = 'Set the transfer proxy of one or more points.' | ||
|
||
exports.builder = function(yargs) { | ||
} | ||
|
||
exports.handler = async function (argv) | ||
{ | ||
const workDir = files.ensureWorkDir(argv.workDir); | ||
const privateKey = await eth.getPrivateKey(argv); | ||
const ctx = await eth.createContext(argv); | ||
const ethAccount = eth.getAccount(ctx.web3, privateKey); | ||
|
||
const wallets = argv.useWalletFiles ? findPoints.getWallets(workDir) : null; | ||
const points = findPoints.getPoints(argv, workDir, wallets); | ||
|
||
console.log(`Will set transfer proxy for ${points.length} points`); | ||
for (const p of points) | ||
{ | ||
let patp = ob.patp(p); | ||
console.log(`Trying to set transfer proxy for ${patp} (${p}).`); | ||
|
||
let wallet = argv.useWalletFiles ? wallets[patp] : null; | ||
let targetAddress = | ||
argv.address != undefined | ||
? argv.address | ||
: argv.useWalletFiles | ||
? wallet.ownership.keys.address : | ||
null; //fail | ||
targetAddress = validate.address(targetAddress, true); | ||
|
||
if(await azimuth.isTransferProxy(ctx.contracts, p, targetAddress)){ | ||
console.log(`Target address ${targetAddress} is already transfer proxy for ${patp}.`); | ||
continue; | ||
} | ||
|
||
var res = await ajs.check.canSetTransferProxy(ctx.contracts, p, ethAccount.address); | ||
if(!res.result){ | ||
console.log(`Cannot set transfer proxy for ${patp}: ${res.reason}`); | ||
continue; | ||
} | ||
|
||
//create and send tx | ||
let tx = ajs.ecliptic.setTransferProxy(ctx.contracts, p, targetAddress) | ||
await eth.setGasSignSendAndSaveTransaction(ctx, tx, privateKey, argv, workDir, patp, 'transferproxy'); | ||
} //end for each point | ||
|
||
process.exit(0); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const ob = require('urbit-ob') | ||
const _ = require('lodash') | ||
const ajsUtils = require('azimuth-js').utils; | ||
var Accounts = require('web3-eth-accounts'); | ||
const {files, validate, eth, findPoints, rollerApi} = require('../../utils') | ||
|
||
exports.command = 'transfer-proxy' | ||
exports.desc = 'Set the transfer proxy of one or more L2 points.' | ||
|
||
exports.builder = function(yargs) { | ||
} | ||
|
||
exports.handler = async function (argv) | ||
{ | ||
const rollerClient = rollerApi.createClient(argv); | ||
const workDir = files.ensureWorkDir(argv.workDir); | ||
const privateKey = await eth.getPrivateKey(argv); | ||
const account = new Accounts().privateKeyToAccount(privateKey); | ||
const signingAddress = account.address; | ||
|
||
const wallets = argv.useWalletFiles ? findPoints.getWallets(workDir) : null; | ||
const points = findPoints.getPoints(argv, workDir, wallets); | ||
|
||
console.log(`Will set transfer proxy for ${points.length} points`); | ||
for (const p of points) | ||
{ | ||
let patp = ob.patp(p); | ||
console.log(`Trying to set transfer proxy for ${patp} (${p}).`); | ||
|
||
const pointInfo = await rollerApi.getPoint(rollerClient, patp); | ||
if(pointInfo.dominion != 'l2'){ | ||
console.log(`This point in not on L2, please use the L1 modify command.`); | ||
continue; | ||
} | ||
|
||
let wallet = argv.useWalletFiles ? wallets[patp] : null; | ||
let targetAddress = | ||
argv.address != undefined | ||
? argv.address | ||
: argv.useWalletFiles | ||
? wallet.ownership.keys.address : | ||
null; //fail | ||
targetAddress = validate.address(targetAddress, true); | ||
|
||
if(ajsUtils.addressEquals(pointInfo.ownership.transferProxy.address, targetAddress)){ | ||
console.log(`Target address ${targetAddress} is already transfer proxy for ${patp}.`); | ||
continue; | ||
} | ||
|
||
//the proxy type must be 'own', indicating that the signing address is the same as the point owner, | ||
// bc only the point owner can set the mgmt proxy | ||
if((await rollerApi.getManagementProxyType(rollerClient, patp, signingAddress)) != 'own'){ | ||
console.log(`Cannot set transfer proxy for ${patp}, must be owner.`); | ||
continue; | ||
} | ||
|
||
//create and send tx | ||
var receipt = await rollerApi.setTransferProxy(rollerClient, patp, targetAddress, signingAddress, privateKey); | ||
console.log("Tx hash: "+receipt.hash); | ||
|
||
let receiptFileName = patp.substring(1)+`-receipt-L2-${receipt.type}.json`; | ||
files.writeFile(workDir, receiptFileName, receipt); | ||
} //end for each point | ||
|
||
process.exit(0); | ||
}; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The wallet.json has
ownership.keys
andtransfer.keys
so I'm not sure which is the correct one to use here.My assumption is that the goal is for the point to end up being owned by the ownership key, so I should set the transfer proxy to the ownership key and then the ownership key will use the transfer proxy rights to transfer the point to itself. But then I don't see what is the point of the separate "transfer" keys in the wallet.