Skip to content
This repository has been archived by the owner on Mar 14, 2021. It is now read-only.

Commit

Permalink
feat: add segregated witness structure
Browse files Browse the repository at this point in the history
  • Loading branch information
ashchan committed Apr 1, 2019
1 parent 37368f0 commit a418daf
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CKB.xcodeproj/project.pbxproj
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 50;
objectVersion = 51;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -31,6 +31,7 @@
1A414AA521C7713800B28C09 /* UtilsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1A414AA421C7713800B28C09 /* UtilsTests.swift */; };
1AB45ED7222AA558009B395B /* Secp256k1.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB45ED6222AA558009B395B /* Secp256k1.swift */; };
1AB45EDA222AA644009B395B /* Secp256k1Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AB45ED9222AA644009B395B /* Secp256k1Tests.swift */; };
1AE7C62C2251BCA9003FA254 /* Witness.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1AE7C62B2251BCA9003FA254 /* Witness.swift */; };
2D6EA000E9B8936CB81356CC /* Pods_CKB.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6F4BD554CBEED5D384A1C737 /* Pods_CKB.framework */; };
591DADB7D11BC8F71DBF4902 /* Pods_CKBTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6FD2179DE52A415B08B8D134 /* Pods_CKBTests.framework */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -73,6 +74,7 @@
1A414AA421C7713800B28C09 /* UtilsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UtilsTests.swift; sourceTree = "<group>"; };
1AB45ED6222AA558009B395B /* Secp256k1.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Secp256k1.swift; sourceTree = "<group>"; };
1AB45ED9222AA644009B395B /* Secp256k1Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Secp256k1Tests.swift; sourceTree = "<group>"; };
1AE7C62B2251BCA9003FA254 /* Witness.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Witness.swift; sourceTree = "<group>"; };
3280C4848C7A8236CA5F4CD8 /* Pods-CKBTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CKBTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CKBTests/Pods-CKBTests.debug.xcconfig"; sourceTree = "<group>"; };
5CAEE4335089142E8F3ECC55 /* Pods-CKBTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CKBTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-CKBTests/Pods-CKBTests.release.xcconfig"; sourceTree = "<group>"; };
5CD9DB4E09DDB6450D81BC6F /* Pods-CKB.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CKB.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CKB/Pods-CKB.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -182,6 +184,7 @@
1A414A9921C3879500B28C09 /* Cell.swift */,
1A414A8D21C3722300B28C09 /* CellInput.swift */,
1A414A8F21C3723E00B28C09 /* CellOutput.swift */,
1AE7C62B2251BCA9003FA254 /* Witness.swift */,
1A414A8721C36FCF00B28C09 /* Header.swift */,
1A414A8921C36FE900B28C09 /* Block.swift */,
1A414A8B21C3714E00B28C09 /* Transaction.swift */,
Expand Down Expand Up @@ -449,6 +452,7 @@
1A414A7B21C22A9300B28C09 /* APIClient.swift in Sources */,
1AB45ED7222AA558009B395B /* Secp256k1.swift in Sources */,
1A414A8E21C3722300B28C09 /* CellInput.swift in Sources */,
1AE7C62C2251BCA9003FA254 /* Witness.swift in Sources */,
1A414A9621C37AA000B28C09 /* Script.swift in Sources */,
1A414AA021C770DD00B28C09 /* Utils.swift in Sources */,
1A414A9A21C3879500B28C09 /* Cell.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Source/Types/Header.swift
Expand Up @@ -20,6 +20,7 @@ public struct Header: Codable {
public let number: BlockNumber
public let txsCommit: H256
public let txsProposal: H256
public let witnessesRoot: H256
public let difficulty: UInt256
public let cellbaseId: H256
public let unclesHash: H256
Expand All @@ -35,6 +36,7 @@ public struct Header: Codable {
case number
case txsCommit = "txs_commit"
case txsProposal = "txs_proposal"
case witnessesRoot = "witnesses_root"
case difficulty
case cellbaseId = "cellbase_id"
case unclesHash = "uncles_hash"
Expand Down
14 changes: 12 additions & 2 deletions Source/Types/Transaction.swift
Expand Up @@ -13,13 +13,22 @@ public struct Transaction: Codable, Param {
public let deps: [OutPoint]
public let inputs: [CellInput]
public let outputs: [CellOutput]
public let witnesses: [Witness]
public let hash: H256

public init(version: UInt32 = 0, deps: [OutPoint] = [], inputs: [CellInput] = [], outputs: [CellOutput] = [], hash: H256 = "") {
public init(
version: UInt32 = 0,
deps: [OutPoint] = [],
inputs: [CellInput] = [],
outputs: [CellOutput] = [],
witnesses: [Witness] = [],
hash: H256 = ""
) {
self.version = version
self.deps = deps
self.inputs = inputs
self.outputs = outputs
self.witnesses = witnesses
self.hash = hash
}

Expand All @@ -28,7 +37,8 @@ public struct Transaction: Codable, Param {
"version": version,
"deps": deps.map { $0.param },
"inputs": inputs.map { $0.param },
"outputs": outputs.map { $0.param }
"outputs": outputs.map { $0.param },
"witnesses": witnesses.map { $0.param }
]
}
}
21 changes: 21 additions & 0 deletions Source/Types/Witness.swift
@@ -0,0 +1,21 @@
//
// Witness.swift
// CKB
//
// Created by James Chen on 2019/04/01.
// Copyright © 2019 Nervos Foundation. All rights reserved.
//

import Foundation

public struct Witness: Codable, Param {
public let index: UInt32
public let data: [HexString]

public var param: [String: Any] {
return [
"index": index,
"data": data
]
}
}

0 comments on commit a418daf

Please sign in to comment.