Skip to content

Commit f5f1e9c

Browse files
committed
Adds changes to fix witness_set_properties
1 parent bb32283 commit f5f1e9c

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

doc/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,28 @@ steem.broadcast.feedPublish(wif, publisher, exchangeRate, function(err, result)
18941894
});
18951895
```
18961896
- - - - - - - - - - - - - - - - - -
1897+
### Build Witness Update Properties
1898+
```
1899+
const owner = 'starlord28'
1900+
const props = {
1901+
"key": "Public Signing Key", // MANDATORY
1902+
"new_signing_key": "Public Signing Key", // optional
1903+
"account_creation_fee": "3.000 STEEM", // optional
1904+
"account_subsidy_budget": 0, // optional
1905+
"account_subsidy_decay": 0, // optional
1906+
"maximum_block_size": 65536, // optional
1907+
"sbd_interest_rate": "0.000 STEEM", // optional
1908+
"sbd_exchange_rate": {"base": "0.237 SBD", "quote": "1.000 STEEM"}, // optional
1909+
"url": "https://steemcryptic.me", // optional
1910+
}
1911+
1912+
const witnessOps = steem.utils.buildWitnessSetProperties(props);
1913+
1914+
steem.broadcast.witnessSetProperties('Private Signing Key', owner, witnessOps, [], function(err, result) {
1915+
console.log(err, result);
1916+
});
1917+
```
1918+
- - - - - - - - - - - - - - - - - -
18971919
### Fill Convert Request
18981920
```js
18991921
steem.broadcast.fillConvertRequest(wif, owner, requestid, amountIn, amountOut, function(err, result) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@steemit/steem-js",
3-
"version": "0.7.11",
3+
"version": "0.7.12",
44
"description": "Steem.js the JavaScript API for Steem blockchain",
55
"main": "lib/index.js",
66
"scripts": {

src/auth/serializer/src/operations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ let account_create_with_delegation = new Serializer(
661661
let witness_set_properties = new Serializer(
662662
"witness_set_properties", {
663663
owner: string,
664-
props: string,
664+
props: map(string, bytes()),
665665
extensions: set(future_extensions)
666666
}
667667
);

src/utils.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
2+
import types from "./auth/serializer/src/types"
3+
import Serializer from "./auth/serializer/src/serializer"
4+
import ByteBuffer from '@exodus/bytebuffer'
5+
6+
let price = new Serializer(
7+
"price", {
8+
base: types.asset,
9+
quote: types.asset
10+
}
11+
);
12+
const propTypes = {
13+
key: types.public_key,
14+
new_signing_key: types.public_key,
15+
account_creation_fee: types.asset,
16+
account_subsidy_budget: types.uint32,
17+
account_subsidy_decay: types.uint32,
18+
maximum_block_size: types.uint32,
19+
sbd_interest_rate: types.uint16,
20+
sbd_exchange_rate: price,
21+
url: types.string
22+
};
123
const snakeCaseRe = /_([a-z])/g;
224
export function camelCase(str) {
325
return str.replace(snakeCaseRe, function(_m, l) {
@@ -43,3 +65,31 @@ export function validateAccountName(value) {
4365
}
4466
return null;
4567
}
68+
69+
function serialize(serializer, data) {
70+
const buffer = new ByteBuffer(
71+
ByteBuffer.DEFAULT_CAPACITY,
72+
ByteBuffer.LITTLE_ENDIAN
73+
);
74+
serializer.appendByteBuffer(buffer, data);
75+
buffer.flip();
76+
return buffer.toString('hex');
77+
}
78+
79+
export function buildWitnessSetProperties(props) {
80+
const data = [];
81+
82+
for (const [key, value] of Object.entries(props)) {
83+
const type = propTypes[key];
84+
85+
if (!type) {
86+
throw new Error(`Unknown witness property: ${key}`);
87+
}
88+
89+
data.push([key, serialize(type, value)]);
90+
}
91+
92+
data.sort((a, b) => a[0].localeCompare(b[0]));
93+
94+
return data;
95+
}

0 commit comments

Comments
 (0)