From 283a4ff3a8dbd57cc4b5a24d82b2b769a3151fc1 Mon Sep 17 00:00:00 2001 From: nixer89 Date: Sun, 31 Mar 2019 23:04:12 +0200 Subject: [PATCH 1/3] initial commit for adding an emailHash and a domain to your XRPL account --- src/commands/account.ts | 7 +++++ .../account/account-set-transaction.ts | 13 +++++++++ src/commands/account/domain.ts | 28 ++++++++++++++++++ src/commands/account/email.ts | 29 +++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 src/commands/account.ts create mode 100644 src/commands/account/account-set-transaction.ts create mode 100644 src/commands/account/domain.ts create mode 100644 src/commands/account/email.ts diff --git a/src/commands/account.ts b/src/commands/account.ts new file mode 100644 index 0000000..663dfb5 --- /dev/null +++ b/src/commands/account.ts @@ -0,0 +1,7 @@ +import { Argv } from 'yargs' + +export const command = 'account ' +export const describe = `Set a Domain and/or Avatar on your XRP ledger account` +export const builder = (argv: Argv) => { + return argv.commandDir('account') +} diff --git a/src/commands/account/account-set-transaction.ts b/src/commands/account/account-set-transaction.ts new file mode 100644 index 0000000..d856f58 --- /dev/null +++ b/src/commands/account/account-set-transaction.ts @@ -0,0 +1,13 @@ +import { api, getXrpAddressAndSecret, signSubmitVerify } from '../../utils/xrp' +import { FormattedTransactionType } from 'ripple-lib'; + + +export async function AccountSet (fields :any): Promise { + + const { address, secret } = await getXrpAddressAndSecret(); + + const prepared = await (await api()).prepareSettings(address, fields); + console.log('AccountSet transaction prepared...'); + + return signSubmitVerify(prepared, secret); +} diff --git a/src/commands/account/domain.ts b/src/commands/account/domain.ts new file mode 100644 index 0000000..407b8c9 --- /dev/null +++ b/src/commands/account/domain.ts @@ -0,0 +1,28 @@ +import { Options } from 'yargs' +import { AccountSet } from './account-set-transaction'; + +export type Params = { + domain?: string +} +export const command = 'domain [domain]' +export const describe = `Sets a domain on the XRP ledger account. Leave empty to delete your domain.` +export const builder: { [key: string]: Options } = { + domain: { + type: 'string', + required: false, + description: 'domain to set on your XRPL account' + } +} + +export async function handler ({ domain }: Params) { + + let result = await AccountSet({domain: domain ? domain : ''}); + + console.log(JSON.stringify(result, null, 2)) + + if (result.outcome.result === 'tesSUCCESS') { + console.log('Domain set to: ' + domain) + process.exit(0) + } + process.exit(1) +} diff --git a/src/commands/account/email.ts b/src/commands/account/email.ts new file mode 100644 index 0000000..3fbf2aa --- /dev/null +++ b/src/commands/account/email.ts @@ -0,0 +1,29 @@ +import { Options } from 'yargs' +import { AccountSet } from './account-set-transaction'; + +export type Params = { + emailHash?: string +} +export const command = 'email [email]' +export const describe = `Sets an email for the XRP ledger account to show the avatar. Leave empty to delete avatar.` +export const builder: { [key: string]: Options } = { + emailHash: { + type: 'string', + required: false, + description: 'emailHash to set on your XRPL account' + } +} + +export async function handler ({ emailHash }: Params) { + + let result = await AccountSet({emailHash: emailHash ? emailHash : ''}); + + console.log(JSON.stringify(result, null, 2)) + + if (result.outcome.result === 'tesSUCCESS') { + console.log('emailHash set to: ' + emailHash) + process.exit(0) + } + process.exit(1) +} + From 053b775b80f93efedd10e13a35c33bdd3ddaa406 Mon Sep 17 00:00:00 2001 From: Daniel Siedentopf Date: Mon, 1 Apr 2019 11:11:37 +0200 Subject: [PATCH 2/3] make emailHash an required argument + smaller fixes --- src/commands/account/account-set-transaction.ts | 2 +- src/commands/account/domain.ts | 10 +++++++--- src/commands/account/{email.ts => emailHash.ts} | 14 +++++++------- 3 files changed, 15 insertions(+), 11 deletions(-) rename src/commands/account/{email.ts => emailHash.ts} (52%) diff --git a/src/commands/account/account-set-transaction.ts b/src/commands/account/account-set-transaction.ts index d856f58..99a6e13 100644 --- a/src/commands/account/account-set-transaction.ts +++ b/src/commands/account/account-set-transaction.ts @@ -2,7 +2,7 @@ import { api, getXrpAddressAndSecret, signSubmitVerify } from '../../utils/xrp' import { FormattedTransactionType } from 'ripple-lib'; -export async function AccountSet (fields :any): Promise { +export async function execute (fields :any): Promise { const { address, secret } = await getXrpAddressAndSecret(); diff --git a/src/commands/account/domain.ts b/src/commands/account/domain.ts index 407b8c9..ef2a94f 100644 --- a/src/commands/account/domain.ts +++ b/src/commands/account/domain.ts @@ -1,5 +1,5 @@ import { Options } from 'yargs' -import { AccountSet } from './account-set-transaction'; +import * as accountSet from './account-set-transaction'; export type Params = { domain?: string @@ -16,12 +16,16 @@ export const builder: { [key: string]: Options } = { export async function handler ({ domain }: Params) { - let result = await AccountSet({domain: domain ? domain : ''}); + let result = await accountSet.execute({domain: domain ? domain : ''}); console.log(JSON.stringify(result, null, 2)) if (result.outcome.result === 'tesSUCCESS') { - console.log('Domain set to: ' + domain) + if(domain) + console.log('\nDomain set to: ' + domain) + else + console.log('\nDomain deleted'); + process.exit(0) } process.exit(1) diff --git a/src/commands/account/email.ts b/src/commands/account/emailHash.ts similarity index 52% rename from src/commands/account/email.ts rename to src/commands/account/emailHash.ts index 3fbf2aa..703db60 100644 --- a/src/commands/account/email.ts +++ b/src/commands/account/emailHash.ts @@ -1,27 +1,27 @@ import { Options } from 'yargs' -import { AccountSet } from './account-set-transaction'; +import * as accountSet from './account-set-transaction'; export type Params = { - emailHash?: string + emailHash: string } -export const command = 'email [email]' -export const describe = `Sets an email for the XRP ledger account to show the avatar. Leave empty to delete avatar.` +export const command = 'emailHash ' +export const describe = `Sets an emailHash on the XRP ledger account to show the avatar.` export const builder: { [key: string]: Options } = { emailHash: { type: 'string', - required: false, + required: true, description: 'emailHash to set on your XRPL account' } } export async function handler ({ emailHash }: Params) { - let result = await AccountSet({emailHash: emailHash ? emailHash : ''}); + let result = await accountSet.execute({emailHash: emailHash}); console.log(JSON.stringify(result, null, 2)) if (result.outcome.result === 'tesSUCCESS') { - console.log('emailHash set to: ' + emailHash) + console.log('\nemailHash set to: ' + emailHash) process.exit(0) } process.exit(1) From fa3d5349b1a05df82ece286660e228f339838881 Mon Sep 17 00:00:00 2001 From: nixer89 Date: Mon, 1 Apr 2019 13:44:53 +0200 Subject: [PATCH 3/3] added new account setting transaction to README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 7a714b8..88ab943 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,12 @@ xrp escrow xrp tx ``` +### Account Settings + +``` +xrp account +``` + ## Contributing This lib has been intentionally designed for easy contribution. To add a command simply submit a PR that adds a new file in the `./src/commands/` folder.