"spend_account": a.wallet.AccountMgr.DecodeSpendAction,
"spend_account_unspent_output": a.wallet.AccountMgr.DecodeSpendUTXOAction,
"dpos_address": a.wallet.AccountMgr.DecodeDposAction,
+ "ipfs_data": txbuilder.DecodeIpfsDataAction,
}
decoder, ok := decoders[action]
return decoder, ok
"os"
"strings"
+ "github.com/vapor/config"
+
ipfs "github.com/ipfs/go-ipfs-api"
"github.com/vapor/common"
"github.com/vapor/consensus"
data
)
+// DecodeIpfsDataAction convert input data to action struct
+func DecodeIpfsDataAction(data []byte) (Action, error) {
+ a := new(dataAction)
+ err := stdjson.Unmarshal(data, a)
+ return a, err
+}
+
type dataAction struct {
- Type uint32 `json:"type"`
+ bc.AssetAmount
+ Type uint32 `json:"data_type"`
Data string `json:"data"`
}
func (a *dataAction) Build(ctx context.Context, b *TemplateBuilder) error {
-
var r io.Reader
switch a.Type {
case file:
- // 检查文件是否存在
fi, err := os.Stat(a.Data)
if os.IsNotExist(err) {
return err
if err != nil {
return err
}
-
case data:
if a.Data == "" {
return errors.New("data is empty")
}
- // 生成文件对象
r = strings.NewReader(a.Data)
default:
}
- // 连接ipfs节点
- sh := ipfs.NewShell("localhost:5001")
+ sh := ipfs.NewShell(config.CommonConfig.IpfsAddress)
cid, err := sh.Add(r)
if err != nil {
return err
}
- fmt.Println(cid)
+ program, err := vmutil.RetireProgram([]byte(cid))
+ if err != nil {
+ return err
+ }
+ out := types.NewTxOutput(*a.AssetId, 0, program)
+ return b.AddOutput(out)
+}
- return nil
+func (a *dataAction) ActionType() string {
+ return "ipfs_data"
}
type BoolArgument struct {
Value bool `json:"value"`
}
+
+// ContractArgument for smart contract
+type IpfsData struct {
+ Type string `json:"type"`
+ Data string `json:"data"`
+}
runNodeCmd.Flags().String("consensus_config_file", config.ConsensusConfigFile, "consensus configuration file")
+ // ipfs address
+ runNodeCmd.Flags().String("IpfsAddress", config.IpfsAddress, "Connect ipfs (eg. 127.0.0.1:5001)")
+
RootCmd.AddCommand(runNodeCmd)
}
Signer string `mapstructure:"signer"`
ConsensusConfigFile string `mapstructure:"consensus_config_file"`
+
+ IpfsAddress string `mapstructure:"ipfs_addr"`
}
// Default configurable base parameters.
DBBackend: "leveldb",
DBPath: "data",
KeysPath: "keystore",
+ IpfsAddress: "127.0.0.1:5001",
}
}
json.Unmarshal(tmp, &blockHeader)
hash := blockHeader.BlockHeader.Hash()
if strings.Compare(consensus.ActiveNetParams.ParentGenesisBlockHash, hash.String()) != 0 {
- log.Error("Invalid parent genesis block hash response via RPC. Contacting wrong parent daemon?", consensus.ActiveNetParams.ParentGenesisBlockHash, hash.String())
+ log.Error("Invalid parent genesis block hash response via RPC. Contacting wrong parent daemon?", consensus.ActiveNetParams.ParentGenesisBlockHash, ":", hash.String())
return false
}
break