-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2251 from elastos/release_v0.9.8
Merge branch release_v0.9.8 into master
- Loading branch information
Showing
22 changed files
with
288,783 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Copyright (c) 2017-2021 The Elastos Foundation | ||
// Use of this source code is governed by an MIT | ||
// license that can be found in the LICENSE file. | ||
// | ||
|
||
package transaction | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
"github.com/elastos/Elastos.ELA/blockchain" | ||
"github.com/elastos/Elastos.ELA/core/types/payload" | ||
elaerr "github.com/elastos/Elastos.ELA/errors" | ||
) | ||
|
||
type RecordSponsorTransaction struct { | ||
BaseTransaction | ||
} | ||
|
||
func (t *RecordSponsorTransaction) HeightVersionCheck() error { | ||
blockHeight := t.parameters.BlockHeight | ||
chainParams := t.parameters.Config | ||
|
||
if t.payloadVersion != 0 { | ||
return errors.New("invalid payload version, need to be zero") | ||
} | ||
|
||
if blockHeight < chainParams.DPoSConfiguration.RecordSponsorStartHeight { | ||
return fmt.Errorf("not support %s transaction before RecordSponsorStartHeight", t.TxType().Name()) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (t *RecordSponsorTransaction) CheckTransactionInput() error { | ||
|
||
if len(t.Inputs()) != 0 { | ||
return errors.New("no cost transactions must has no input") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (t *RecordSponsorTransaction) CheckTransactionOutput() error { | ||
|
||
if len(t.Outputs()) != 0 { | ||
return errors.New("no need to have output in sponsor transaction") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (t *RecordSponsorTransaction) CheckAttributeProgram() error { | ||
|
||
if len(t.Programs()) != 0 { | ||
return errors.New("no need to have program in sponsor transaction") | ||
|
||
} | ||
if len(t.Attributes()) != 1 { | ||
return errors.New("need to have one attribute in sponsor transaction") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (t *RecordSponsorTransaction) CheckTransactionPayload() error { | ||
switch t.Payload().(type) { | ||
case *payload.RecordSponsor: | ||
return nil | ||
} | ||
|
||
return errors.New("invalid payload type") | ||
} | ||
|
||
func (t *RecordSponsorTransaction) IsAllowedInPOWConsensus() bool { | ||
return true | ||
} | ||
|
||
func (t *RecordSponsorTransaction) SpecialContextCheck() (elaerr.ELAError, bool) { | ||
payloadRecordSponsor, ok := t.Payload().(*payload.RecordSponsor) | ||
if !ok { | ||
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("record sponsor transaction has invalid payload")), true | ||
} | ||
|
||
// check sponsor is in current or last arbitrators | ||
current, last := blockchain.DefaultLedger.Arbitrators.GetCurrentAndLastArbitrators() | ||
exist := false | ||
for _, currentArbiter := range current { | ||
if bytes.Equal(currentArbiter.NodePublicKey, payloadRecordSponsor.Sponsor) { | ||
exist = true | ||
break | ||
} | ||
} | ||
for _, lastArbiter := range last { | ||
if bytes.Equal(lastArbiter.NodePublicKey, payloadRecordSponsor.Sponsor) { | ||
exist = true | ||
break | ||
} | ||
} | ||
if !exist { | ||
return elaerr.Simple(elaerr.ErrTxPayload, errors.New("sponsor is not in current or last arbitrators")), true | ||
} | ||
|
||
return nil, true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package transaction | ||
|
||
import ( | ||
"fmt" | ||
"github.com/elastos/Elastos.ELA/common" | ||
"github.com/elastos/Elastos.ELA/utils" | ||
"testing" | ||
) | ||
|
||
func Test_ReverTxID(t *testing.T) { | ||
str := "65dd4737e9a85030d341653ea21005bb132200a97ad8cc8555f4c28ae2e16d71" | ||
txHash, _ := common.Uint256FromHexString(str) | ||
fmt.Println(common.ToReversedString(*txHash)) | ||
|
||
code, _ := common.HexStringToBytes("2103997349de5629299fd2b8d255c99d6b2047c6fcfa0237e9d1b07e5ac8db45f310ac") | ||
addr, _ := utils.GetAddressByCode(code) | ||
fmt.Println("addr:", addr) | ||
|
||
saddr, _ := utils.GetStakeAddressByCode(code) | ||
fmt.Println("saddr:", saddr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) 2017-2020 The Elastos Foundation | ||
// Use of this source code is governed by an MIT | ||
// license that can be found in the LICENSE file. | ||
// | ||
|
||
package payload | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
|
||
"github.com/elastos/Elastos.ELA/common" | ||
) | ||
|
||
const RecordSponsorVersion byte = 0x00 | ||
|
||
const SponsorMaxLength = 33 | ||
|
||
type RecordSponsor struct { | ||
Sponsor []byte | ||
} | ||
|
||
func (a *RecordSponsor) Data(version byte) []byte { | ||
//TODO: implement RegisterRecord.Data() | ||
return []byte{0} | ||
} | ||
|
||
// Serialize is the implement of SignableData interface. | ||
func (a *RecordSponsor) Serialize(w io.Writer, version byte) error { | ||
err := common.WriteVarBytes(w, a.Sponsor) | ||
if err != nil { | ||
return errors.New("[RecordSponsor], Sponsor serialize failed.") | ||
} | ||
return nil | ||
} | ||
|
||
// Deserialize is the implement of SignableData interface. | ||
func (a *RecordSponsor) Deserialize(r io.Reader, version byte) error { | ||
var err error | ||
a.Sponsor, err = common.ReadVarBytes(r, SponsorMaxLength, | ||
"payload record data") | ||
if err != nil { | ||
return errors.New("[RecordSponsor], Sponsor deserialize failed.") | ||
} | ||
return nil | ||
} |
Oops, something went wrong.