Skip to content

Commit

Permalink
add set peer percentage (#118)
Browse files Browse the repository at this point in the history
* add set peer percentage

* fix commit cred bug

* go fmt
  • Loading branch information
siovanus authored Aug 14, 2020
1 parent c7256fa commit a8f369c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (this *ClientMgr) GetSmartContractEventByBlock(height uint32) ([]*sdkcom.Sm
if err != nil {
return nil, err
}
if data == nil || string(data) == "" || string(data) == "\"\""{
if data == nil || string(data) == "" || string(data) == "\"\"" {
return nil, nil
}
return utils.GetSmartContactEvents(data)
Expand Down
2 changes: 1 addition & 1 deletion cred.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (this *Credential) GetPublicKeyList(ontId string) (PublicKeyList, error) {

func (this *Credential) CommitCredential(contractAddress common.Address, gasPrice, gasLimit uint64, credentialId, issuerId,
holderId string, signer, payer *Account) (common.Uint256, error) {
index, _, err := this.GetPublicKeyId(holderId, hex.EncodeToString(keypair.SerializePublicKey(signer.GetPublicKey())))
index, _, err := this.GetPublicKeyId(issuerId, hex.EncodeToString(keypair.SerializePublicKey(signer.GetPublicKey())))
if err != nil {
return common.UINT256_EMPTY, fmt.Errorf("CommitCredential, this.GetPublicKeyId error: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,4 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087 h1:Izowp2XBH6Ya6rv+hqbceQyw/gSGoXfH/UPoTGduL54=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
launchpad.net/gocheck v0.0.0-20140225173054-000000000087/go.mod h1:hj7XX3B/0A+80Vse0e+BUHsHMTEhd0O4cpUHr/e/BUM=
51 changes: 51 additions & 0 deletions native_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type NativeContract struct {
OntId *OntId
GlobalParams *GlobalParam
Auth *Auth
Governance *Governance
}

func newNativeContract(ontSdk *OntologySdk) *NativeContract {
Expand All @@ -70,6 +71,7 @@ func newNativeContract(ontSdk *OntologySdk) *NativeContract {
native.OntId = &OntId{native: native, ontSdk: ontSdk}
native.GlobalParams = &GlobalParam{native: native, ontSdk: ontSdk}
native.Auth = &Auth{native: native, ontSdk: ontSdk}
native.Governance = &Governance{native: native, ontSdk: ontSdk}
return native
}

Expand Down Expand Up @@ -2878,3 +2880,52 @@ func (this *Auth) VerifyToken(gasPrice, gasLimit uint64, payer, signer *Account,
}
return this.ontSdk.SendTransaction(tx)
}

type Governance struct {
ontSdk *OntologySdk
native *NativeContract
}

type SetFeePercentageParam struct {
PeerPubkey string
Address common.Address
PeerCost uint32
StakeCost uint32
}

func (this *Governance) SetFeePercentageTransaction(gasPrice, gasLimit uint64, peerPubkey string, address common.Address,
peerCost, stakeCost uint32) (*types.MutableTransaction, error) {
params := SetFeePercentageParam{
PeerPubkey: peerPubkey,
Address: address,
PeerCost: peerCost,
StakeCost: stakeCost,
}
return this.native.NewNativeInvokeTransaction(
gasPrice,
gasLimit,
GOVERNANCE_CONTRACT_VERSION,
GOVERNANCE_CONTRACT_ADDRESS,
"setFeePercentage",
[]interface{}{params})
}

func (this *Governance) SetFeePercentage(gasPrice, gasLimit uint64, payer, signer *Account, peerPubkey string,
peerCost, stakeCost uint32) (common.Uint256, error) {
tx, err := this.SetFeePercentageTransaction(gasPrice, gasLimit, peerPubkey, signer.Address, peerCost, stakeCost)
if err != nil {
return common.UINT256_EMPTY, err
}
if payer != nil {
this.ontSdk.SetPayer(tx, payer.Address)
err = this.ontSdk.SignToTransaction(tx, payer)
if err != nil {
return common.UINT256_EMPTY, err
}
}
err = this.ontSdk.SignToTransaction(tx, signer)
if err != nil {
return common.UINT256_EMPTY, err
}
return this.ontSdk.SendTransaction(tx)
}

0 comments on commit a8f369c

Please sign in to comment.