Commit 77d4a3ee authored by Mahdi Yari's avatar Mahdi Yari

Merge branch 'fix-witness_set_properties' into 'master'

Fix witness set properties

Closes #10

See merge request !6
parents 51b7655d 6434ebdf
......@@ -576,6 +576,20 @@ hive.broadcast.accountWitnessVote(wif, account, witness, approve, function(err,
console.log(err, result);
});
```
### Witness Set Properties
```
hive.broadcast.witnessSetProperties(signingKey, owner, props, extensions, function(err, result) {
console.log(err, result);
});
```
|Parameter|Description|Datatype|Notes|
|---|---|---|---|
|signingKey|Private signing key of the witness|String||
|owner|The name of witness account|String||
|props|Witness properties|Array| Use `hive.utils.buildWitnessUpdateOp(owner, props)` to build the values|
|extensions|empty array []|Array||
### Challenge Authority
```
hive.broadcast.challengeAuthority(wif, challenger, challenged, requireOwner, function(err, result) {
......@@ -951,3 +965,26 @@ var isValidUsername = hive.utils.validateAccountName('a1');
console.log(isValidUsername);
// => 'Account name should be longer.'
```
### Build Witness Update Properties
```
const owner = 'mahdiyari'
const props = {
"key": "Public Signing Key" // REQUIRED
"account_creation_fee": "0.000 HIVE", // optional
"account_subsidy_budget": 10000, // optional
"account_subsidy_decay": 330782, // optional
"maximum_block_size": 65536, // optional
"sbd_interest_rate": "0.000 HIVE", // optional
"sbd_exchange_rate": {"base": "0.250 HBD", "quote": "1.000 HIVE"}, // optional
"url": "https://testurl", // optional
"new_signing_key": "Public Signing Key" // optional
}
const witnessOps = hive.utils.buildWitnessUpdateOp(owner, props);
hive.broadcast.witnessSetProperties('Private Signing Key', owner, witnessOps.props, [], function(err, result) {
console.log(err, result);
});
```
{
"name": "@hiveio/hive-js",
"version": "0.8.0",
"version": "0.8.1",
"description": "Hive.js the JavaScript API for Hive blockchain",
"main": "lib/index.js",
"scripts": {
......
......@@ -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)
}
);
......
import types from "./auth/serializer/src/types"
import Serializer from "./auth/serializer/src/serializer"
const ByteBuffer = require('bytebuffer')
const {
uint16,
uint32,
string,
public_key,
asset
} = types
const snakeCaseRe = /_([a-z])/g;
export function camelCase(str) {
return str.replace(snakeCaseRe, function(_m, l) {
......@@ -43,3 +55,63 @@ export function validateAccountName(value) {
}
return null;
}
// Hack to be able to generate a valid witness_set_properties op
// Can hopefully be removed when hived's JSON representation is fixed
const price = new Serializer(
"price", {
base: asset,
quote: asset
}
);
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 buildWitnessUpdateOp(
owner,
props
) {
const data = {
extensions: [],
owner,
props: []
};
for (const key of Object.keys(props)) {
let type;
switch (key) {
case "key":
case "new_signing_key":
type = public_key;
break;
case "account_subsidy_budget":
case "account_subsidy_decay":
case "maximum_block_size":
type = uint32;
break;
case "sbd_interest_rate":
type = uint16;
break;
case "url":
type = string;
break;
case "sbd_exchange_rate":
type = price;
break;
case "account_creation_fee":
type = asset;
break;
default:
throw new Error(`Unknown witness prop: ${key}`);
}
data.props.push([key, serialize(type, props[key])]);
}
data.props.sort((a, b) => a[0].localeCompare(b[0]));
return ["witness_set_properties", data];
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment