• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

balzac-lang / balzac / #345

27 Feb 2025 10:03AM UTC coverage: 57.806%. Remained the same
#345

push

web-flow
Merge b3d2b6910 into 697afd4f2

822 of 1422 relevant lines covered (57.81%)

0.58 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.67
/xyz.balzaclang.balzac.lib/src/main/java/xyz/balzaclang/lib/model/script/InputScript.java
1
/*
2
 * Copyright 2020 Nicola Atzei
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package xyz.balzaclang.lib.model.script;
17

18
import static com.google.common.base.Preconditions.checkState;
19

20
import org.bitcoinj.script.Script;
21
import org.bitcoinj.script.ScriptBuilder;
22

23
public abstract class InputScript extends AbstractScriptBuilderWithVar<InputScript> {
1✔
24

25
    private static final long serialVersionUID = 1L;
26

27
    public boolean isP2SH() {
28
        return this instanceof P2SHInputScript;
1✔
29
    }
30

31
    abstract public OutputScript getRedeemScript();
32

33
    public String getType() {
34
        return isP2SH() ? "P2SH" : "STANDARD";
1✔
35
    }
36

37
    public static InputScript create() {
38
        return new InputScript() {
1✔
39

40
            private static final long serialVersionUID = 1L;
41

42
            @Override
43
            public OutputScript getRedeemScript() {
44
                throw new IllegalStateException("Not a P2SH. Use InputScript.createP2SH");
×
45
            }
46
        };
47
    }
48

49
    public static InputScript createP2SH(OutputScript redeemScript) {
50
        return new P2SHInputScript(redeemScript);
×
51
    }
52

53
    private static class P2SHInputScript extends InputScript {
54

55
        private static final long serialVersionUID = 1L;
56

57
        private final OutputScript redeemScript;
58

59
        private P2SHInputScript(OutputScript redeemScript) {
×
60
            this.redeemScript = redeemScript;
×
61
        }
×
62

63
        @Override
64
        public Script build() {
65
            checkState(redeemScript.isReady(), "redeemScript is not ready");
×
66
            return new ScriptBuilder(super.build()).data(redeemScript.build().getProgram()).build();
×
67
        }
68

69
        @Override
70
        public boolean isReady() {
71
            return super.isReady() && redeemScript.isReady();
×
72
        }
73

74
        public OutputScript getRedeemScript() {
75
            return redeemScript;
×
76
        }
77

78
        @Override
79
        public boolean isP2SH() {
80
            return true;
×
81
        }
82

83
        @Override
84
        public String toString() {
85
            return super.toString() + " <" + redeemScript.toString() + ">";
×
86
        }
87
    }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc