fix parse balance entry and hash parent
This commit is contained in:
parent
a5ceedeb6c
commit
7de884b7e4
@ -1,6 +1,7 @@
|
|||||||
package wallet
|
package wallet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil/base58"
|
"github.com/btcsuite/btcd/btcutil/base58"
|
||||||
@ -152,23 +153,6 @@ func HashSource(source *nockchain.NockchainSource) [5]uint64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HashParent(note *nockchain.NockchainNote) ([5]uint64, error) {
|
|
||||||
nameHash := HashName(note.Name)
|
|
||||||
lockHash, err := HashLock(note.Lock)
|
|
||||||
if err != nil {
|
|
||||||
return [5]uint64{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
sourceHash := HashSource(note.Source)
|
|
||||||
assetHash := crypto.Tip5HashBelts([]crypto.Belt{{Value: 1}, {Value: uint64(note.Asset)}})
|
|
||||||
|
|
||||||
hashSourceAsset := crypto.Tip5RehashTenCell(sourceHash, assetHash)
|
|
||||||
|
|
||||||
q := crypto.Tip5RehashTenCell(nameHash, crypto.Tip5RehashTenCell(lockHash, hashSourceAsset))
|
|
||||||
|
|
||||||
return q, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func HashSeedWithoutSource(seed *nockchain.NockchainSeed) ([5]uint64, error) {
|
func HashSeedWithoutSource(seed *nockchain.NockchainSeed) ([5]uint64, error) {
|
||||||
lockHash, err := HashLock(seed.Recipient)
|
lockHash, err := HashLock(seed.Recipient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -214,6 +198,10 @@ func HashNonce(pkPoint crypto.CheetahPoint, message [5]uint64) ([]crypto.Belt, [
|
|||||||
|
|
||||||
func HashSpend(spend *nockchain.NockchainSpend) ([5]uint64, error) {
|
func HashSpend(spend *nockchain.NockchainSpend) ([5]uint64, error) {
|
||||||
// TODO: handle multiple sig
|
// TODO: handle multiple sig
|
||||||
|
if len(spend.Signatures) == 0 {
|
||||||
|
return [5]uint64{}, fmt.Errorf("signatures can not be empty")
|
||||||
|
}
|
||||||
|
|
||||||
sigHash, err := HashSignature(spend.Signatures[0])
|
sigHash, err := HashSignature(spend.Signatures[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return [5]uint64{}, err
|
return [5]uint64{}, err
|
||||||
@ -386,13 +374,16 @@ func ParseBalanceEntry(entry *nockchain.BalanceEntry) nockchain.NockchainNote {
|
|||||||
},
|
},
|
||||||
Source: &nockchain.NockchainSource{
|
Source: &nockchain.NockchainSource{
|
||||||
Source: crypto.Tip5HashToBase58(sourceHash),
|
Source: crypto.Tip5HashToBase58(sourceHash),
|
||||||
IsCoinbase: entry.Note.Source.Coinbase,
|
IsCoinbase: true,
|
||||||
},
|
},
|
||||||
Asset: entry.Note.Assets.Value,
|
Asset: entry.Note.Assets.Value,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseTimelockIntent(timelock *nockchain.TimeLockIntent) *nockchain.TimelockIntent {
|
func ParseTimelockIntent(timelock *nockchain.TimeLockIntent) *nockchain.TimelockIntent {
|
||||||
|
if timelock == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
switch timelock.Value.(type) {
|
switch timelock.Value.(type) {
|
||||||
case *nockchain.TimeLockIntent_Absolute:
|
case *nockchain.TimeLockIntent_Absolute:
|
||||||
return &nockchain.TimelockIntent{
|
return &nockchain.TimelockIntent{
|
||||||
|
@ -331,20 +331,11 @@ func (h *GprcHandler) CreateTx(ctx context.Context, req *nockchain.CreateTxReque
|
|||||||
var masterKey *crypto.MasterKey
|
var masterKey *crypto.MasterKey
|
||||||
chainCode := base58.Decode(req.ChainCode)
|
chainCode := base58.Decode(req.ChainCode)
|
||||||
key := base58.Decode(req.Key)
|
key := base58.Decode(req.Key)
|
||||||
_, err := crypto.CheetaPointFromBytes(key)
|
masterKey, err := crypto.MasterKeyFromPrivKey(chainCode, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// priv key
|
return nil, err
|
||||||
masterKey, err = crypto.MasterKeyFromPrivKey(chainCode, key)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
masterKey = &crypto.MasterKey{
|
|
||||||
PrivateKey: []byte{},
|
|
||||||
PublicKey: key,
|
|
||||||
ChainCode: chainCode,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !req.IsMasterKey {
|
if !req.IsMasterKey {
|
||||||
index := req.Index
|
index := req.Index
|
||||||
if index > 1<<32 {
|
if index > 1<<32 {
|
||||||
@ -399,7 +390,7 @@ func (h *GprcHandler) CreateTx(ctx context.Context, req *nockchain.CreateTxReque
|
|||||||
return nil, fmt.Errorf("note not enough balance")
|
return nil, fmt.Errorf("note not enough balance")
|
||||||
}
|
}
|
||||||
|
|
||||||
parentHash, err := HashParent(notes[i])
|
parentHash, err := HashNote(notes[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -437,20 +428,18 @@ func (h *GprcHandler) CreateTx(ctx context.Context, req *nockchain.CreateTxReque
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(masterKey.PrivateKey) != 0 {
|
// sign
|
||||||
// sign
|
chalT8, sigT8, err := ComputeSig(*masterKey, msg)
|
||||||
chalT8, sigT8, err := ComputeSig(*masterKey, msg)
|
if err != nil {
|
||||||
if err != nil {
|
return nil, err
|
||||||
return nil, err
|
}
|
||||||
}
|
|
||||||
|
|
||||||
spend.Signatures = []*nockchain.NockchainSignature{
|
spend.Signatures = []*nockchain.NockchainSignature{
|
||||||
{
|
{
|
||||||
Pubkey: base58.Encode(masterKey.PublicKey),
|
Pubkey: base58.Encode(masterKey.PublicKey),
|
||||||
Chal: chalT8[:],
|
Chal: chalT8[:],
|
||||||
Sig: sigT8[:],
|
Sig: sigT8[:],
|
||||||
},
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
input := nockchain.NockchainInput{
|
input := nockchain.NockchainInput{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user