Skip to content

Commit b9c3850

Browse files
committed
Merge branch 'pluswave-bsip0038'
2 parents c604b14 + 3f882cd commit b9c3850

7 files changed

Lines changed: 466 additions & 73 deletions

File tree

examples/callOrderUpdate.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {Apis} from "bitsharesjs-ws";
2+
import {TransactionBuilder, PrivateKey} from "../lib";
3+
4+
const wifKey = "5KBuq5WmHvgePmB7w3onYsqLM8ESomM2Ae7SigYuuwg8MDHW7NN";
5+
const pKey = PrivateKey.fromWif(wifKey);
6+
7+
Apis.instance("wss://node.testnet.bitshares.eu", true).init_promise.then(
8+
res => {
9+
console.log("connected to:", res[0].network_name, "network");
10+
11+
let tr = new TransactionBuilder();
12+
tr.add_type_operation("call_order_update", {
13+
funding_account: "1.2.680",
14+
delta_collateral: {
15+
amount: 1000000,
16+
asset_id: "1.3.0"
17+
},
18+
delta_debt: {
19+
amount: 0,
20+
asset_id: "1.3.1003"
21+
},
22+
extensions: {
23+
target_collateral_ratio: 250
24+
}
25+
});
26+
27+
tr.set_required_fees().then(() => {
28+
tr.add_signer(pKey, pKey.toPublicKey().toPublicKeyString());
29+
console.log("serialized transaction:", tr.serialize().operations);
30+
tr
31+
.broadcast()
32+
.then(() => {
33+
console.log("Call order update success!");
34+
})
35+
.catch(err => {
36+
console.error(err);
37+
});
38+
});
39+
}
40+
);

examples/publishFeed.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import {Apis} from "bitsharesjs-ws";
2+
import {TransactionBuilder, PrivateKey} from "../lib";
3+
4+
const wifKey = "5KBuq5WmHvgePmB7w3onYsqLM8ESomM2Ae7SigYuuwg8MDHW7NN";
5+
const pKey = PrivateKey.fromWif(wifKey);
6+
7+
Apis.instance("wss://node.testnet.bitshares.eu", true).init_promise.then(
8+
res => {
9+
console.log("connected to:", res[0].network_name, "network");
10+
let tr = new TransactionBuilder();
11+
tr.add_type_operation("asset_publish_feed", {
12+
publisher: "1.2.680",
13+
asset_id: "1.3.1003",
14+
feed: {
15+
settlement_price: {
16+
quote: {
17+
amount: 10,
18+
asset_id: "1.3.0"
19+
},
20+
base: {
21+
amount: 5,
22+
asset_id: "1.3.1003"
23+
}
24+
},
25+
maintenance_collateral_ratio: 1750,
26+
maximum_short_squeeze_ratio: 1200,
27+
core_exchange_rate: {
28+
quote: {
29+
amount: 10,
30+
asset_id: "1.3.0"
31+
},
32+
base: {
33+
amount: 5,
34+
asset_id: "1.3.1003"
35+
}
36+
}
37+
}
38+
});
39+
40+
tr.set_required_fees().then(() => {
41+
tr.add_signer(pKey, pKey.toPublicKey().toPublicKeyString());
42+
console.log("serialized transaction:", tr.serialize().operations);
43+
tr
44+
.broadcast()
45+
.then(() => {
46+
console.log("Publish feed success!");
47+
})
48+
.catch(err => {
49+
console.error(err);
50+
});
51+
});
52+
}
53+
);

lib/serializer/src/operations.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ var {
2323
public_key,
2424
address,
2525
time_point_sec,
26-
optional
26+
optional,
27+
indexed_optional,
28+
extension
2729
} = types;
2830

2931
future_extensions = types.void;
@@ -485,12 +487,19 @@ export const limit_order_cancel = new Serializer("limit_order_cancel", {
485487
extensions: set(future_extensions)
486488
});
487489

490+
export const call_order_update_options = new Serializer(
491+
"call_order_update_options",
492+
{
493+
target_collateral_ratio: indexed_optional(uint16, 0)
494+
}
495+
);
496+
488497
export const call_order_update = new Serializer("call_order_update", {
489498
fee: asset,
490499
funding_account: protocol_id_type("account"),
491500
delta_collateral: asset,
492501
delta_debt: asset,
493-
extensions: set(future_extensions)
502+
extensions: extension(call_order_update_options)
494503
});
495504

496505
export const fill_order = new Serializer("fill_order", {

lib/serializer/src/types.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,100 @@ Types.optional = function(st_operation) {
684684
};
685685
};
686686

687+
Types.indexed_optional = function(st_operation, index) {
688+
v.required(st_operation, "st_operation");
689+
return {
690+
fromByteBuffer(b) {
691+
if (!(b.readVarint32() === index)) {
692+
return undefined;
693+
}
694+
return st_operation.fromByteBuffer(b);
695+
},
696+
appendByteBuffer(b, object) {
697+
if (object !== null && object !== undefined) {
698+
b.writeVarint32(index);
699+
st_operation.appendByteBuffer(b, object);
700+
}
701+
return;
702+
},
703+
fromObject(object) {
704+
if (object === undefined) {
705+
return undefined;
706+
}
707+
return st_operation.fromObject(object);
708+
},
709+
toObject(object, debug = {}) {
710+
// toObject is only null save if use_default is true
711+
var result_object = (() => {
712+
if (!debug.use_default && object === undefined) {
713+
return undefined;
714+
} else {
715+
return st_operation.toObject(object, debug);
716+
}
717+
})();
718+
719+
if (debug.annotate) {
720+
if (typeof result_object === "object") {
721+
result_object.__optional = "parent is optional";
722+
} else {
723+
result_object = {__optional: result_object};
724+
}
725+
}
726+
return result_object;
727+
}
728+
};
729+
};
730+
731+
Types.extension = function(st_operation) {
732+
v.required(st_operation, "st_operation");
733+
return {
734+
fromByteBuffer(b) {
735+
if (!(b.readVarint32() === 1)) {
736+
return undefined;
737+
}
738+
return st_operation.fromByteBuffer(b);
739+
},
740+
appendByteBuffer(b, object) {
741+
if (
742+
object !== null &&
743+
object !== undefined &&
744+
!(typeof object == "object" && Object.keys(object).length == 0)
745+
) {
746+
b.writeVarint32(1);
747+
st_operation.appendByteBuffer(b, object);
748+
} else {
749+
b.writeVarint32(0);
750+
}
751+
return;
752+
},
753+
fromObject(object) {
754+
if (object === undefined) {
755+
return undefined;
756+
}
757+
return st_operation.fromObject(object);
758+
},
759+
toObject(object, debug = {}) {
760+
// toObject is only null save if use_default is true
761+
var result_object = (() => {
762+
if (!debug.use_default && object === undefined) {
763+
return undefined;
764+
} else {
765+
return st_operation.toObject(object, debug);
766+
}
767+
})();
768+
769+
if (debug.annotate) {
770+
if (typeof result_object === "object") {
771+
result_object.__optional = "parent is optional";
772+
} else {
773+
result_object = {__optional: result_object};
774+
}
775+
}
776+
return result_object;
777+
}
778+
};
779+
};
780+
687781
Types.static_variant = function(_st_operations) {
688782
return {
689783
nosort: true,

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
"prepublish": "npm run build && npm run test",
2727
"doc": "esdoc -c esdoc.json",
2828
"example:transfer": "babel-node examples/transfer",
29+
"example:feed": "babel-node examples/publishFeed",
30+
"example:co-update": "babel-node examples/callOrderUpdate",
2931
"example:chainStore": "babel-node examples/chainStore",
3032
"example:privKey": "babel-node examples/privKey"
3133
},

0 commit comments

Comments
 (0)