A Governance Object (or "govObject") is a generic structure introduced in Dash Core v12.1 to allow for the creation of Budget Proposals, Triggers, and Watch Dogs. Class inheritance has been utilized to extend this generic object into a "Proposal" which is outlined throughout the remainder of this document.
Creates a new GovObject
object where:
govObjectData
- optional data (allowed types arejson
,jsonString
,hex
,buffer
,GovObject
)
Returns a dataHex representation (see above)
Allow to create a govObj from a json or stringifiedJSON obj
Allow to create a govObj from a hex string
Return a hex string that can be used in dashd CLI
Return a hex string
Returns a representation of the object
Return a buffer
Allow to create a govObject from a buffer
Allow to shallowCopy from another govObject
The following would create a blank govObject
// instantiate a new govObject instance
var govObject = new GovObject();
Budget Proposals can be created from a valid JSON object (stringified or not)
var jsonProposal = {
name: 'My First GovObject',
start_epoch: 1483228800,
end_epoch: 1483747200,
payment_address: 'yXGeNPQXYFXhLAN1ZKrAjxzzBnZ2JZNKnh',
payment_amount: 10,
type: 1,
url: 'http://www.dash.org/proposal/first_proposal',
};
// Will instantiate the govObject given the json passed as arg for fromObject
govObject = govObject.fromObject(jsonProposal);
var govObject = new GovObject().fromObject(jsonProposal);
// It's worth mentioning that fromObject can also be a valid stringified json.
var govObject = new GovObject().fromObject(JSON.stringify(jsonProposal));
Budget Proposals can be instantiated from a Buffer
// Allow creation of a new object from a given buffer
var fromBuff = new GovObject(govObjBuffer);
// Or
var fromBuff = new GovObject().fromBuffer(govObjBuffer);
// And from a hex string
var fromString = new GovObject('7b226e616d65223a224...');
// or
var fromString = new GovObject().fromString('7b226e616d65223a224...');
You can display a hex-encoded representation of a Budget Proposal with a simple "toString()"
var fromString = new GovObject('7b226e616d65223a224...');
var hexString = fromString.toString();
// or
var hexString = fromString.serialize();
Logging the object will also return a hex-encoded representation of the object
var fromString = new GovObject('7b226e616d65223a224...');
console.log(fromString); // <GovObject: 7b226e616d65223a224...>
// Or using the method
fromString.inspect();
You could shallowcopy a first govObj into a second one
proposal.url = 'http://dash.org/badUrl';
var shallowCopyProposal = proposal.shallowCopy();
proposal.url = 'http://dash.org/fixedUrl';
console.log(proposal.url !== shallowCopyProposal.url); // return true as it's a copy
console.log(proposal !== shallowCopyProposal); // return true
Finally you are able to get the dataHex from the object
var fromString = new GovObject('7b226e616d65223a224...');
// Give a stringified json [['proposal',{name:"My First GovObject",....}]]
fromString.dataHex();
// You could get back the given JSON object by doing so
var JSONObject = JSON.parse(fromString.dataHex());
Each of these types are inherited from govObject allowing the same methods to be callable.
- Proposal
type:1
: Allow to create a proposal which inherit govObject method and overwrite them when needed
var jsonProposal = {
name: 'My First Proposal',
start_epoch: startDate,
end_epoch: endDate,
payment_address: 'yXGeNPQXYFXhLAN1ZKrAjxzzBnZ2JZNKnh',
payment_amount: 10,
type: 1,
url: 'http://www.dash.org',
};
var proposal = new Proposal();
// create a new proposal from a stringified JSON object
proposal = proposal.fromObject(JSON.stringify(jsonProposal));
// As proposal inherits govObject
var shallowCopy = proposal.shallowCopy();
// Return a hex equivalent of the proposal
var hexProposal = proposal.serialize();