diff --git a/doc/README.md b/doc/README.md index 06fda515..c4b38c3e 100644 --- a/doc/README.md +++ b/doc/README.md @@ -1894,6 +1894,28 @@ steem.broadcast.feedPublish(wif, publisher, exchangeRate, function(err, result) }); ``` - - - - - - - - - - - - - - - - - - +### Build Witness Update Properties +``` +const owner = 'starlord28' +const props = { + "key": "Public Signing Key", // MANDATORY + "new_signing_key": "Public Signing Key", // optional + "account_creation_fee": "3.000 STEEM", // optional + "account_subsidy_budget": 0, // optional + "account_subsidy_decay": 0, // optional + "maximum_block_size": 65536, // optional + "sbd_interest_rate": "0.000 STEEM", // optional + "sbd_exchange_rate": {"base": "0.237 SBD", "quote": "1.000 STEEM"}, // optional + "url": "https://steemcryptic.me", // optional +} + +const witnessOps = steem.utils.buildWitnessSetProperties(props); + +steem.broadcast.witnessSetProperties('Private Signing Key', owner, witnessOps, [], function(err, result) { + console.log(err, result); +}); +``` +- - - - - - - - - - - - - - - - - - ### Fill Convert Request ```js steem.broadcast.fillConvertRequest(wif, owner, requestid, amountIn, amountOut, function(err, result) { diff --git a/package.json b/package.json index bd194091..64e582c4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@steemit/steem-js", - "version": "0.7.11", + "version": "0.7.12", "description": "Steem.js the JavaScript API for Steem blockchain", "main": "lib/index.js", "scripts": { diff --git a/src/auth/serializer/src/operations.js b/src/auth/serializer/src/operations.js index b6573e06..a76299d9 100644 --- a/src/auth/serializer/src/operations.js +++ b/src/auth/serializer/src/operations.js @@ -661,7 +661,7 @@ let account_create_with_delegation = new Serializer( let witness_set_properties = new Serializer( "witness_set_properties", { owner: string, - props: string, + props: map(string, bytes()), extensions: set(future_extensions) } ); diff --git a/src/utils.js b/src/utils.js index 253541ff..be45aaf6 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,3 +1,25 @@ + +import types from "./auth/serializer/src/types" +import Serializer from "./auth/serializer/src/serializer" +import ByteBuffer from '@exodus/bytebuffer' + +let price = new Serializer( + "price", { + base: types.asset, + quote: types.asset +} +); +const propTypes = { + key: types.public_key, + new_signing_key: types.public_key, + account_creation_fee: types.asset, + account_subsidy_budget: types.uint32, + account_subsidy_decay: types.uint32, + maximum_block_size: types.uint32, + sbd_interest_rate: types.uint16, + sbd_exchange_rate: price, + url: types.string +}; const snakeCaseRe = /_([a-z])/g; export function camelCase(str) { return str.replace(snakeCaseRe, function(_m, l) { @@ -43,3 +65,31 @@ export function validateAccountName(value) { } return null; } + +function serialize(serializer, data) { + const buffer = new ByteBuffer( + ByteBuffer.DEFAULT_CAPACITY, + ByteBuffer.LITTLE_ENDIAN + ); + serializer.appendByteBuffer(buffer, data); + buffer.flip(); + return buffer.toString('hex'); +} + +export function buildWitnessSetProperties(props) { + const data = []; + + for (const [key, value] of Object.entries(props)) { + const type = propTypes[key]; + + if (!type) { + throw new Error(`Unknown witness property: ${key}`); + } + + data.push([key, serialize(type, value)]); + } + + data.sort((a, b) => a[0].localeCompare(b[0])); + + return data; +}