OSDN Git Service

refactor: use derived xpubs for federation (#289) node_path
authorHAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
Mon, 15 Jul 2019 14:16:13 +0000 (22:16 +0800)
committerPaladz <yzhu101@uottawa.ca>
Mon, 15 Jul 2019 14:16:13 +0000 (22:16 +0800)
* add fed path

* refactor: rename FedPath

* clean

blockchain/txbuilder/actions.go
config/genesis.go

index ff83650..8021f35 100644 (file)
@@ -293,7 +293,7 @@ func (a *crossInAction) Build(ctx context.Context, builder *TemplateBuilder) err
        txin := types.NewCrossChainInput(nil, a.SourceID, *a.AssetId, a.Amount, a.SourcePos, a.VMVersion, a.RawDefinitionByte, a.IssuanceProgram)
        tplIn := &SigningInstruction{}
        fed := cfg.CommonConfig.Federation
-       tplIn.AddRawWitnessKeys(fed.Xpubs, nil, fed.Quorum)
+       tplIn.AddRawWitnessKeys(fed.Xpubs, cfg.FedAddressPath, fed.Quorum)
        tplIn.AddDataWitness(cfg.FederationPMultiSigScript(cfg.CommonConfig))
        return builder.AddInput(txin, tplIn)
 }
index aabb430..4c8e62e 100644 (file)
@@ -13,9 +13,18 @@ import (
        "github.com/vapor/protocol/vm/vmutil"
 )
 
+var FedAddressPath = [][]byte{
+       []byte{0x2C, 0x00, 0x00, 0x00},
+       []byte{0x99, 0x00, 0x00, 0x00},
+       []byte{0x01, 0x00, 0x00, 0x00},
+       []byte{0x00, 0x00, 0x00, 0x00},
+       []byte{0x01, 0x00, 0x00, 0x00},
+}
+
 func FederationPMultiSigScript(c *Config) []byte {
        xpubs := c.Federation.Xpubs
-       program, err := vmutil.P2SPMultiSigProgram(chainkd.XPubKeys(xpubs), c.Federation.Quorum)
+       derivedXPubs := chainkd.DeriveXPubs(xpubs, FedAddressPath)
+       program, err := vmutil.P2SPMultiSigProgram(chainkd.XPubKeys(derivedXPubs), c.Federation.Quorum)
        if err != nil {
                log.Panicf("fail to generate federation scirpt for federation: %v", err)
        }